5
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
<Result>
  <resultDetails>
    <resultDetailsData>
      <itemProperties>
        <ID>1</ID>
        <type>LEVEL</type> 
        <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">5</value> 
      </itemProperties>
    </resultDetailsData>
  </resultDetails>
</Result>

I have the xml described above. I want to get the value of value tag (in this case, '5') using the value of the type tag, (i.e., LEVEL in this case) and store it in a variable using XSLT, so that i can use the variable later.

How do I do it?

2 Answers 2

8

You could do it this way:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">

<xsl:template match="/">
    <xsl:variable name="myVar" select="Result/resultDetails/resultDetailsData/itemProperties/value"/>
<varoutput>
    <xsl:value-of select="$myVar"/>
</varoutput>
</xsl:template> 

</xsl:stylesheet>

Applied to your input XML you get this output:

<?xml version="1.0" encoding="UTF-8"?>
<varoutput>5</varoutput>
Sign up to request clarification or add additional context in comments.

Comments

2

If you want to use the read variable to set an attribute (i.e. color of a row) you need to use {$variable} as below

<xsl:variable name="rColor" select="rowColor"/>

then

<fo:table-row background-color="{$rColor}">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.