[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl: parsing through specific child nodes

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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.