[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: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Sun, 7 Sep 2008 22:47:52 +0530
Re:  xsl: parsing through specific child nodes
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-2011 All Rights Reserved.