[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Comparing attributes and setting the values

Subject: Re: [xsl] Comparing attributes and setting the values
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 22 Aug 2014 09:20:35 -0000

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">
      <xsl:copy-of select="//Item"/>
      <xsl:copy-of select="$doc2//Item"/>

        <xsl:template match="@*|node()">
                <xsl:apply-templates select="@*|node()"/>

<xsl:template match="text()" priority="5"/>

<xsl:template match="PackNumber/@level">
<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:element name="counter">
<xsl:attribute name="level">
<xsl:value-of select="count(preceding::PackNumber[not(preceding::PackNumber/@level= .)])"/>

                <xsl:value-of select="."/>

<xsl:template match="/">
<xsl:apply-templates select="exsl:node-set($merge-doc)//Item"/>

Current Thread