[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Rewrite xpath to not use variable references
Hello again! With help from the members of this list over the past year, we were able to put our first release into production. Thank you so much for your generosity! Moving on, how do I need to change my xpath to use pure xpath - no variables? I want to visit each /root/w node and print the correct /root/a/b/c value. I am getting the correct output, but have had to rely on variable references. Desired output: Value: red. Value: juicy. Xml: <?xml version="1.0" encoding="UTF-8"?> <root> <w x="1" y="AA" z="BB">apple</w> <w x="1" y="AA" z="CC">orange</w> <a ID="1"> <b> <c d="AA">apple</c> <c d="BB">red</c> <c d="CC">crisp</c> <c d="DD">fruit</c> </b> <b> <c d="AA">orange</c> <c d="BB">orange</c> <c d="CC">juicy</c> <c d="DD">fruit</c> </b> <b> <c d="AA">banana</c> <c d="BB">yellow</c> <c d="CC">soft</c> <c d="DD">fruit</c> </b> </a> <a ID="2"> <b> <c d="AA">potato</c> <c d="BB">red</c> <c d="CC">crisp</c> <c d="DD">tuber</c> </b> </a> </root> XSL: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"> <xsl:output method="text"/> <xsl:key name="fruit" match="/root/a" use="@ID"/> <xsl:template match="w"> <xsl:variable name="w" select="." as="xs:string"/> <xsl:variable name="y" select="@y" as="xs:string"/> <xsl:variable name="z" select="@z" as="xs:string"/> Value: <xsl:value-of select="key('fruit', @x)/b/c[@d = $y and .=$w]/../c[@d eq $z]"/>. </xsl:template> <xsl:template match="c"/> </xsl:stylesheet> Thanks! Angela
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|