Subject: Re: [xsl] xsl: parsing through specific child nodes From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Sat, 6 Sep 2008 09:38:21 +0530 |
Please find below the solution. Let's say the two XML documents be: x.xml <ZZ> <ABC>XXXXX</ABC> <DEF>YYYYYY</DEF> </ZZ> y.xml <ZZ> <ABC>AAAAA</ABC> <DEF>FFFFFFF</DEF> </ZZ> The stylesheet is: test.xsl <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes" /> <xsl:variable name="x" select="document('x.xml')" /> <xsl:variable name="y" select="document('y.xml')" /> <xsl:template match="/"> <Body> <xsl:apply-templates select="$x/ZZ" /> <xsl:apply-templates select="$y/ZZ" /> </Body> </xsl:template> <xsl:template match="ZZ"> <ZZ> <xsl:apply-templates select="*" /> </ZZ> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:choose> <xsl:when test=". = 'YYYYYY'"> <xsl:text>DDDDD</xsl:text> </xsl:when> <xsl:when test=". = 'GGGGGG'"> <xsl:text>EEEEEE</xsl:text> </xsl:when> <xsl:otherwise> <xsl:value-of select="." /> </xsl:otherwise> </xsl:choose> </xsl:copy> </xsl:template> </xsl:stylesheet> Supposing this is run with Xalan-J as: java org.apache.xalan.xslt.Process -in test.xsl -xsl test.xsl The output is: <?xml version="1.0" encoding="UTF-8"?> <Body> <ZZ> <ABC>XXXXX</ABC> <DEF>DDDDD</DEF> </ZZ> <ZZ> <ABC>AAAAA</ABC> <DEF>FFFFFFF</DEF> </ZZ> </Body> On Fri, Sep 5, 2008 at 10:47 PM, Mohit Anchlia <mohitanchlia@xxxxxxxxx> wrote: > one more question, for above scenario should I be using xsl:key for > mapping purposes. for eg: If I want to change value from A to B for > certain node types? I don't think xsl:key can be useful in this scenario. -- Regards, Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] xsl: parsing through specific, Mohit Anchlia | Thread | Re: [xsl] xsl: parsing through spec, Mohit Anchlia |
[xsl] xsl: parsing through specific, Mohit Anchlia | Date | Re: [xsl] xsl: parsing through spec, Mohit Anchlia |
Month |