[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] XSLT 2.0: Definition of a structure and its use
Hi all, I'm trying to emulate a definition of a structure and a call to the definition in XML. I'm having trouble getting the required output. (Note: this message was posted on the XSL list, but I don't have a solution yet). Input XML is : <a> <b offset="5"> <reg>reg_1</reg> <reg>reg_2</reg> <reg href="REGDEF1"></reg> <!-- this is the call to a structure --> <reg>reg_3</reg> </b> <!-- this is the definition of the structure --> <regdef name="REGDEF1"> <reg>reg_10</reg> <reg>reg_20</reg> </regdef> </a> XSLT is : <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="reg[@href]"> <xsl:variable name="reg_href"> <xsl:copy-of select="//regdef[@name=current()/@href]"/> </xsl:variable> <xsl:apply-templates select="$reg_href/*"/> </xsl:template> <xsl:template match="regdef"/> <xsl:template match="reg"> <br/>Register : <xsl:value-of select="."/> Offset = <xsl:value-of select="../@offset"/> Prev-Sibling count = <xsl:value-of select="count(preceding-sibling::reg)"/> </xsl:template> </xsl:stylesheet> Output is : Register : reg_1 Offset = 5 Prev-Sibling count = 0 Register : reg_2 Offset = 5 Prev-Sibling count = 1 Register : reg_3 Offset = 5 Prev-Sibling count = 3 I want the output to say: Register : reg_1 Offset = 5 Prev-Sibling count = 0 Register : reg_2 Offset = 5 Prev-Sibling count = 1 Register : reg_10 Offset = 5 Prev-Sibling count = 2 Register : reg_20 Offset = 5 Prev-Sibling count = 3 Register : reg_3 Offset = 5 Prev-Sibling count = 4 Thanks, Anupam. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
|
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
|