1

I am new in XSLT, and am learning how to store attribute into a variable.

I have a scenario where my input xml file is :

<?xml version="1.0" encoding="UTF-8"?>
<books>
    <book title="ABC" id="1">
         <infos>
            <info key="pages">200</info>
            <info key="price">$1.50</info>
         </infos>
    </book>
    <book title="XYZ" id="1">
         <infos>
            <info key="pages">300</info>
            <info key="price">$3.00</info>
         </infos>
    </book>
</books>

I want to know how to store the title of a book whose pages is 200, i.e. i need the "ABC" to be stored in a variable.

I have searched many places but all I could find is how to store the last attributes value by using this code :

  <xsl:variable name="pages" select="/*/info[.='200']/@key"/>

where i can get the $key value as "pages", but i want title's value

Is is possible to get title's value by using similar approach, if yes then where am i going wrong, Thanks in Advance

2
  • <xsl:variable name="pages" select="/*/info[.='200']/@key"/> does not contain anything. Commented Apr 20, 2016 at 21:27
  • no it was just the code which i understood would work, have tried it properly afterwards. Commented Apr 22, 2016 at 6:30

1 Answer 1

1

how to store the title of a book whose pages is 200

Try:

<xsl:variable name="title" select="/books/book[infos/info[@key='pages']=200]/@title" />
Sign up to request clarification or add additional context in comments.

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.