[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] How can I change the attribute value of element
Subject: Re: [xsl] How can I change the attribute value of element From: "varun bhatnagar varun292006@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 3 Sep 2014 07:29:09 -0000 |
Hi, I am still stuck with this problem. Any suggestions on this. Thanks, Varun On Mon, Sep 1, 2014 at 2:30 PM, varun bhatnagar varun292006@xxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > Hi, > > I have 2 xmls. I am trying to merge them on certain condition where, if > the xml file contains <test1> element then the pkg tag should be changed to: > <pkg> > <test1 val="12345"/> > </pkg> > and then <pkg1> tag should start. But in the output I am getting <pkg> tag > twice. Any suggestion on how can I remove this tag and have only one <pkg> > tag with the required value? > > File1.xml > <?xml version="1.0"?> > <Move-Afile> > <Afile> > <Item> > <PackNumber level="1"> > <pkg> > <test1 val="41"></test1> > </pkg> > <pkg1> > <all/> > </pkg1> > </PackNumber> > </Item> > <Item> > <PackNumber level="1"> > <pkg> > <test1 val="51"></test1> > </pkg> > <pkg1> > <all/> > </pkg1> > </PackNumber> > </Item> > </Afile> > </Move-Afile> > > File2.xml > <?xml version="1.0"?> > <Move-Afile> > <Afile> > <Item> > <PackNumber level="2"> > <pkg> > <test1 val="12"></test1> > </pkg> > <pkg1> > <all/> > </pkg1> > </PackNumber> > </Item> > <Item> > <PackNumber level="2"> > <pkg> > <test1 val="43"></test1> > </pkg> > <pkg1> > <all/> > </pkg1> > </PackNumber> > </Item> > </Afile> > </Move-Afile> > > Output.xml > > <A> > <target> > <Item> > <PackNumber> > <counter level="1"/> > <pkg> > <test1 val="12345"/> > </pkg> > > <pkg1> > <all/> > </pkg1> > </PackNumber> > </Item> > <Item> > <PackNumber> > <counter level="1"/> > <pkg> > <test1 val="12345"/> > </pkg> > > <pkg1> > <all/> > </pkg1> > </PackNumber> > </Item> > <Item> > <PackNumber> > <counter level="2"/> > <pkg> > <test1 val="12345"/> > </pkg> > <pkg> > <test1 val="12"/> > </pkg> > </PackNumber> > </Item> > <Item> > <PackNumber> > <counter level="2"/> > <pkg> > <test1 val="12345"/> > </pkg> > <pkg> > <test1 val="43"/> > </pkg> > </PackNumber> > </Item> > </target> > </A> > > Rules.xsl > <?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="2.0"> > <xsl:output indent="yes" omit-xml-declaration="yes"/> > <xsl:template match="@*|node()" mode="step2"> > <xsl:copy> > <xsl:apply-templates select="@*|node()" mode="step2"/> > </xsl:copy> > </xsl:template> > > > <xsl:template match="@*|node()" mode="step3"> > <xsl:copy> > <xsl:apply-templates select="@*|node()" mode="step3"/> > </xsl:copy> > </xsl:template> > > <xsl:template match="@*|node()" mode="step4"> > <xsl:copy> > <xsl:apply-templates select="@*|node()" mode="step4"/> > </xsl:copy> > </xsl:template> > > <xsl:template match="text()"/> > > <xsl:template match="Item" mode="step1"> > <xsl:copy-of select="."/> > </xsl:template> > > <!-- > <xsl:template match="//test1/@val"> > <xsl:value-of select="1234"></xsl:value-of> > </xsl:template> > --> > <xsl:template match="PackNumber/@level" mode="step3"> > <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> > <xsl:text>
</xsl:text> > <pkg> > <xsl:text>
</xsl:text> > <test1 val="12345"/> > <xsl:text>
</xsl:text> > </pkg> > <xsl:apply-templates select="//pkg1"></xsl:apply-templates> > </xsl:template> > > <!-- <xsl:template match="//pkg"></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> > </xsl:template> > > <xsl:template match="/"> > <xsl:variable name="union"> > <xsl:apply-templates select="//Item" mode="step1"/> > <xsl:apply-templates select="document('stackoverflow2.xml')/*//Item" > mode="step1"/> > </xsl:variable> > <A> > <target> > <xsl:choose> > <xsl:when test="exsl:node-set($union)/*/descendant::test"> > <xsl:apply-templates select="exsl:node-set($union)/*" mode="step2"/> > </xsl:when> > <xsl:otherwise> > <xsl:apply-templates select="exsl:node-set($union)/*" mode="step3"/> > </xsl:otherwise> > </xsl:choose> > </target> > </A> > </xsl:template> > </xsl:stylesheet> > > BR, > Varun > XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list> > EasyUnsubscribe <-list/2562907> (by > email <>)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How can I change the attribut, varun bhatnagar varu | Thread | [xsl] namespace problem, Ruud Grosmann r.gros |
[xsl] How can I change the attribut, varun bhatnagar varu | Date | [xsl] namespace problem, Ruud Grosmann r.gros |
Month |