Subject: Re: [xsl] xsl: parsing through specific child nodes From: "Mohit Anchlia" <mohitanchlia@xxxxxxxxx> Date: Sun, 7 Sep 2008 12:46:01 -0700 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] xsl: parsing through spec, Mukul Gandhi | Thread | Re: [xsl] xsl: parsing through spec, Mukul Gandhi |
Re: [xsl] xsl: parsing through spec, Mukul Gandhi | Date | [xsl] Java XSLT transformers and do, LS |
Month |