dimanche 25 juin 2017

Extracting a value from XML and storing it in a variable

here is my sample XML :

<Entries>
    <Entry>
       <id>1</id>
     .
     .
     </Entry>

     <Entry>
       <id>2</id>
       <assets> 
          <TextAssetInfo>
             <Name>Alpha</Name>
             <TagName>alphaName</TagName>
             <value>Harambe</value>
          </TextAssetInfo>
       </assets>
     </Entry>
<Entries>

So my goal is simply to extract the value of Alpha and store it in a variable in my XSLT for further computation.

I am able extract and print the value. But not assign in to a variable.

Following part of XSL code works:

<T_AlphaName><xsl:value-of select="./assets/*[Tagname = 'alphaName']/value"/></T_AlphaName>

However, I can't get the below to work :

 <xsl:variable name="myVar" select="./assets/*[attrTagName = 'alphaName']/value"/>

I have tried many other combinations as well but no luck. What am I doing wrong? In my XSL I have part to test it and get a weird result

<TestVar><xsl:value-of select="$myVar"/></TestVar>

 Result : <TestVar/>

Additional info : Using XML/XSL version 1.0. AlphaName is not the only TextAssetInfo inside the assets. There are many more.




Aucun commentaire:

Enregistrer un commentaire