[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: Sun, 7 Sep 2008 12:46:01 -0700
Re:  xsl: parsing through specific child nodes
Thanks so much for the replies. Based on the replies I got I have some
more questions. I will have access to the system on Monday when I can
try these things, and that's why I might be asking something that I
could find out on Monday, so pardon me.

1. So would above template mentioned by Mukul also output node HIJ ?

2. In response from Michael I made some changes to the template, could
you please see if that's the right way:

<?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:element name="{name()}" namespace="{namespace-uri()}">
   <xsl:copy>
     <xsl:choose>
       <xsl:when test="local-name()="HIJ" and . = 'YYYYYY'">
         <xsl:text>DDDDD</xsl:text>
       </xsl:when>
       <xsl:when test="local-name()="HIJ" and . = 'GGGGGG'">
         <xsl:text>EEEEEE</xsl:text>
       </xsl:when>
       <xsl:otherwise>
         <xsl:value-of select="." />
       </xsl:otherwise>
     </xsl:choose>
   </xsl:copy>
  </xsl:element>
 </xsl:template>

</xsl:stylesheet>

I added local-name and also element node. I haven't tried it yet,
which I will do it on Monday.

3. Currently I am using XSLT 1.0 and I am using JAXP which uses Xalan.
How do I start using XSLT 2.0. Would it just be matter of upping
version in stylesheet node?

On Sun, Sep 7, 2008 at 10:17 AM, Mukul Gandhi <gandhi.mukul@xxxxxxxxx> wrote:
> I believe, Mike has suggested quite useful points, which are useful to
> think about.
>
> My reply are mentioned below ..
>
> On Sun, Sep 7, 2008 at 5:53 AM, Mohit Anchlia <mohitanchlia@xxxxxxxxx> wrote:
>> Will this work if I add one more node inside DEF. Something like:
>>
>> <ZZ>
>>  <ABC>XXXXX</ABC>
>>  <DEF>
>>      <HIJ>YYYYYY<HIJ>
>>  </DEF>
>>  </ZZ>
>
> I wrote the template,
>
> <xsl:template match="ZZ">
>   <ZZ>
>     <xsl:apply-templates select="*" />
>   </ZZ>
> </xsl:template>
>
> The xsl:apply-template above will cause all child elements of ZZ to be
> processed.
>
> I wrote another template after that,
>
> <xsl:template match="*">  [1]
>  ....
>
> This template handles any element node. But this template will get
> called for element children of, ZZ (for the problem you posted).
>
> Now let's say the template [1] above is handling the element, DEF. Now
> if my context node is, DEF and I do, <xsl:when test=". = 'YYYYYY'">
> then I am actually checking is, if the string value of DEF is 'YYYYYY'
> or not. For your new example above, the string value of element node
> DEF is YYYYYY plus some whitespaces. So you should ideally do,
> <xsl:when test="normalize-space(.) = 'YYYYYY'">
>
> PS: you should read what the string value of element nodes mean in
> XPath data model.
>
>> 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.
>
> If my element, ABC is defined as:
>
> <ABC xmnls:ns2="http://">
>
> and the node, ABC is supplied to the template rule:
>
> <xsl:template match="*">
>
> then this template has in it's context the element ABC. Now what you
> need to do with this element is up to you .. You can choose to copy
> this element as it is, or copy just the element and not the namespaces
> (or, attributes). Mike has answered how to copy namespaces in XSLT 1.0
> and XSLT 2.0.
>
>
> --
> 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-2007 All Rights Reserved.