Subject: Re: [xsl] Calling xsl: template through mode attribute prints only text nodes From: "varun bhatnagar varun292006@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 29 Aug 2014 08:48:50 -0000 |
Hi Martin, Thanks for replying. I have a variable in which I have my Item tag. I have one template defined for PackageNumber/@level (which is inside Item) for which I have set mode="step2". I want to call the same functionality of this template but with few modification. So I want to create 2 more templates for PackageNumber/@level with mode="step3" and mode="step4". I will call these based on certain conditions using apply-template tag like this, <xsl:apply-templates select="PackNumber/@level" mode="step2" />; <xsl:apply-templates select="PackNumber/@level" mode="step3" /> and <xsl:apply-templates select="PackNumber/@level" mode="step4" /> This is what I am trying: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" exclude-result-prefixes="exsl" version="1.0"> <xsl:output indent="yes" omit-xml-declaration="yes"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="text()" /> <xsl:template match="Item" mode="step1"> <xsl:copy-of select="." /> </xsl:template> <xsl:template match="PackNumber/@level" mode="step2"> <xsl:choose> <xsl:when test="not(preceding::PackNumber/@level =.)"> <xsl:element name="counter"> <xsl:attribute name="level"> <xsl:value-of select="count(preceding::PackNumber/@level[not(preceding::PackNumber/@level= .)])+1"/> </xsl:attribute> </xsl:element> </xsl:when> <xsl:otherwise> <xsl:element name="counter"> <xsl:attribute name="level"> <xsl:value-of select="count(preceding::PackNumber/@level[not(preceding::PackNumber/@level= .)])"/> </xsl:attribute> </xsl:element> </xsl:otherwise> </xsl:choose> <PNumber> <xsl:value-of select="."/> </PNumber> </xsl:template> <xsl:template match="PackNumber/@level" mode="step3"> ....Some rules here....... </xsl:template> <xsl:template match="PackNumber/@level" mode="step4"> ....Some rules here....... </xsl:template> <xsl:template match="/"> <xsl:variable name="union"> <xsl:apply-templates select="//Item" mode="step1" /> <xsl:apply-templates select="document('File2.xml')/*//Item" mode="step1" /> </xsl:variable> <A> <target> <xsl:choose> <xsl:when test="Condition1"> <xsl:apply-templates select="exsl:node-set($union)/*" mode="step2" /> </xsl:when> <xsl:when test="Condition2"> <xsl:apply-templates select="exsl:node-set($union)/*" mode="step3" /> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="exsl:node-set($union)/*" mode="step4" /> </xsl:otherwise> </xsl:choose> </target> </A> </xsl:template> </xsl:stylesheet> I read in O'Relly's XSLT book that to process same set of nodes several times, use mode attribute of xsl:template element. I want to do the same. But if I call the template using mode it is printing only the text nodes. How can I print the node-sets? Thanks, Varun
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Calling xsl: template thr, Martin Honnen martin | Thread | Re: [xsl] Calling xsl: template thr, Martin Honnen martin |
Re: [xsl] Code to Translate XSLT Fu, Marc van Grootel mar | Date | Re: [xsl] Calling xsl: template thr, Martin Honnen martin |
Month |