XSLT match text then following sibling

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tgow
    New Member
    • Apr 2009
    • 8

    XSLT match text then following sibling

    Hi Everyone,

    I have the following XML:

    Code:
    <input type ="Data">
          <parameter name ="Name">
                 <variable type="Static">
                        <![CDATA[site]]>
                 </variable>
          </parameter>
          <parameter name="Value">
                 <variable type="Static">
                        <![CDATA[joe]]>
                 </variable>
          </parameter>
    </input>
    I need to match the variable text(site) and grab the variable text(joe). I am not sure how to use the "following-sibling" syntax in this example.

    Thanks in advance,

    Todd
    Last edited by Dormilich; Apr 2 '09, 05:14 AM. Reason: added [code] tags
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by tgow
    I need to match the variable text(site) and grab the variable text(joe).
    could you elaborate? I do not understand the requirement.

    if you want to match text(joe) from text(site) it would be
    Code:
    ancestor::parameter/following-sibling::parameter/variable

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      ??
      Code:
      <xsl:variable name="name" select="'site'"/>
      <xsl:value-of select="//input[parameter[@name = 'Name'] = $name]/parameter[@name='Value']"/>

      Comment

      • tgow
        New Member
        • Apr 2009
        • 8

        #4
        I have a large XML files that repeats the following XML:

        Code:
         
        <script>
          <action>
            <actions>
             <postdata>
                <input type="Data">
                    <parameter name="Name">
                       <variable type="Static">
                          <![CDATA[trans]]>
                       </variable>
                    <parameter name="Value">
                        <variable type="Static">
                          <![CDATA[hello]]>
                    </variable>
                </input>
                <input type="Data">
                    <parameter name="Name">
                       <variable type="Static">
                          <![CDATA[site]]>
                       </variable>
                    <parameter name="Value">
                        <variable type="Static">
                          <![CDATA[joe]]>
                    </variable>
                </input>
        
        ......
        I have written the following xsl which pulls it but the XPATH is hardcoded:

        Code:
        <xsl:value-of select="//script/actions/action/postdata/input[@type = 'Data'][2]/parameter[@name = 'Value']"</xsl:value-of>
        Each XML file is the same but the "<input></input>" order could be different so I really need the "<parameter name="Value"> CDATA value which is "joe" but this will be different every time. I was trying to look for the "<parameter name="Name">" CDATA value which is "site" because this is consistent and grab the "following::sib ling" possibly.

        I hope this makes more sense.

        Thanks again,

        Todd

        Comment

        • jkmyoung
          Recognized Expert Top Contributor
          • Mar 2006
          • 2057

          #5
          replace the [2] with
          [parameter[@name = 'Name'] = 'site']

          Comment

          • tgow
            New Member
            • Apr 2009
            • 8

            #6
            Thanks for the reply. This gets me closer but it is just a Boolean true/false. What I would like to do in pseudo-code is if the following:

            if (site = true) exists
            then
            grab the following-sibling value (joe)

            Do I need to use a variable for this or the choose logic?

            Thanks in advance,

            Todd

            Comment

            • jkmyoung
              Recognized Expert Top Contributor
              • Mar 2006
              • 2057

              #7
              ? If you already know the value is joe, why bother grabbing it?

              Comment

              • tgow
                New Member
                • Apr 2009
                • 8

                #8
                The value of "joe" is dynamic. The value of "site" is static. If I find "site" the I need the following sibling which is the value of "joe" in my example but it could be anything.

                Thanks again,

                Todd

                Comment

                • jkmyoung
                  Recognized Expert Top Contributor
                  • Mar 2006
                  • 2057

                  #9
                  I don't understand what was wrong with the solution:
                  Code:
                  <xsl:value-of select="//script/actions/action/postdata/input[@type = 'Data'][parameter[@name = 'Name'] = 'site']/parameter[@name = 'Value']"/>

                  Comment

                  • tgow
                    New Member
                    • Apr 2009
                    • 8

                    #10
                    It works..thanks for you help.

                    Just an issue between the chair and the keyboard. ;^)

                    Thanks again,

                    Todd

                    Comment

                    Working...