[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Comparing attributes and setting the values
varun bhatnagar varun292006@xxxxxxxxx wrote:
I have posted the details in the above mails. But I can give you the details. I am trying to merge 2 xml files which is having "level" attribute. The condition is, if the level attribute is equal in the same xml file then it should set the same level for that element. But if the level attribute is having different value then it should print the next value in sequential order. As already suggested by Michael, you could do the merging in one step and then apply your existing code to the merged document. Using XSLT 1.0 you need the exsl:node-set function: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" exclude-result-prefixes="exsl"> <xsl:output indent="yes"/> <xsl:param name="doc2-uri" select="'file2.xml'"/> <xsl:variable name="doc2" select="document($doc2-uri)"/> <xsl:variable name="merge-doc"> <Move-Afile> <Afile> <xsl:copy-of select="//Item"/> <xsl:copy-of select="$doc2//Item"/> </Afile> </Move-Afile> </xsl:variable> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="text()" priority="5"/> <xsl:template match="PackNumber/@level"> <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[not(preceding::PackNumber/@level= .)])"/> </xsl:attribute> </xsl:element> </xsl:otherwise> </xsl:choose> <PNumber> <xsl:value-of select="."/> </PNumber> </xsl:template> <xsl:template match="/"> <A> <target> <xsl:apply-templates select="exsl:node-set($merge-doc)//Item"/> </target> </A> </xsl:template> </xsl:stylesheet>
|
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
|