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

Re: [xsl] xsl: parsing through specific child nodes


Subject: Re: [xsl] xsl: parsing through specific child nodes
From: "Mohit Anchlia" <mohitanchlia@xxxxxxxxx>
Date: Sat, 6 Sep 2008 17:23:43 -0700

thanks. Will this work if I add one more node inside DEF. Something like:

<ZZ>
  <ABC>XXXXX</ABC>
  <DEF>
      <HIJ>YYYYYY<HIJ>
  </DEF>
 </ZZ>


One more question regarding "<xsl:apply-templates select="*" />". Is
this going to be applied for each node and attribute also? So for eg:
if I have <ABC xmnls:ns2="http://"> would "<template match=*>" be
called for ABC and then xmnls:ns2 also. Reason I am asking is that I
have scenario where I want to get rid of xmnls:ns2.

On Fri, Sep 5, 2008 at 9:08 PM, Mukul Gandhi <gandhi.mukul@xxxxxxxxx> wrote:
> 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
Keywords
xml