[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: XSL variable out of scope
Hi Nischal. Instead of relying so much on variables, maybe you should use XPath more. For instance, given your xml structure, the XPath expression "/PhoneList/Phone[PhoneUseCode='BUS']/PhoneNumber" would return all PhoneNumber elements that go with businesses. So really you don't have to store these numbers ahead of time. If you need some help with XPath, there's plenty of good online references and tutorials. Hope I was some help, Andy -----Original Message----- From: Nischal Muthana [mailto:nischal_muthana@xxxxxxxxx] Sent: Thursday, January 23, 2003 2:04 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: XSL variable out of scope Hi All, I have an xml and xsl like the following. When I apply the xsl I need to get the following HTML Home: 4089888888 Business: 40888888 But I get an error saying variable out of scope. And I know I am using a variable declared in a different scope. I am kinda stuck here and I dont have any more ideas to counter this. Can someone help me find a way to tackle this problem. PhoneList.xml <?xml-stylesheet type="text/xsl" href="C:\TestXSLT\xsl\PhoneList.xsl"?> <PhoneList> <Phone> <PhoneUseCode>BUS</PhoneUseCode> <PhoneNumber>4082389033</PhoneNumber> </Phone> <Phone> <PhoneUseCode>HOME</PhoneUseCode> <PhoneNumber>4082834798</PhoneNumber> </Phone> </PhoneList> PhoneList.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="/"> <xsl:for-each select="//PhoneList/Phone"> <xsl:variable name="PhUseCode" select="PhoneUseCode"/> <xsl:choose> <xsl:when test="$PhUseCode='HOME'"> <xsl:variable name="HomePhone" select="PhoneNumber"/> </xsl:when> <xsl:when test="$PhUseCode='BUS'"> <xsl:variable name="BusPhone" select="PhoneNumber"/> </xsl:when> </xsl:choose> </xsl:for-each> <tr> <td> </td><td> </td> <td nowrap="nowrap" colspan="2">   Home</td> <td nowrap="nowrap">"<xsl:value-of select="$HomePhone"/></td> </tr> <tr> <td> </td> <td> </td> <td nowrap="nowrap" colspan="2">   Business</td> <td nowrap="nowrap"><xsl:value-of select="$BusPhone"/></td> </tr> </xsl:template> </xsl:stylesheet> __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|