Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Select multiple nodes in XSL

Reply
Thread Tools

Select multiple nodes in XSL

 
 
Michael
Guest
Posts: n/a
 
      12-02-2004
Hello,

I am creating an XSL that is going to create a report from XML we
recieve from another system. The XML would look like:

<report>
<page>
<header1>
<data1>asdf</data1>
<data2>fdas</data2>
</header1>
<header2>
<dataA>xyz</dataA>
<dataB>zyx</dataB>
</header2>
<reportSection1>
<!-- Some Data Here -->
</reportSection1>
<reportSection2>
<!-- Some More Data Here -->
</reportSection2>
</page>
</report>

Due to the size of the XML, I'm attempting to modularize the XSL. I
want to pull out the data for the header into a seperate template.
Currently I have the template as:

<xsl:template match="header1 | header2">
<!-- rest of the template -->
</xsl:template>

And I call it by:

<xsl:apply-templates select="header1 | header2"/>

The issue I'm having is that my XSL is being executed twice, once for
each node (header1 and header2) rather than going thru both nodes at
once. The goal is to go thru both nodes at once. Any assistance
would be appreciated.

Thanks,
Michael
 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      12-02-2004

> <xsl:template match="header1 | header2">
> <!-- rest of the template -->
> </xsl:template>
>
> And I call it by:
>
> <xsl:apply-templates select="header1 | header2"/>
>
> The issue I'm having is that my XSL is being executed twice, once for
> each node (header1 and header2) rather than going thru both nodes at
> once. The goal is to go thru both nodes at once. Any assistance
> would be appreciated.
>
>


you select all header1 and header2 nodes and apply templates to them,
each of those templates is going to execute
-- rest of the template --
actualy they may be executed in any (time) order but the results will be
merged in to the result tree based on position of the nodes in the
source.

So since you have a header1 and a header2 in your example source you get
the results of transforming those nodes.

I can't guess from your description what result you _did_ want so can't
suggest any change to the xsl. It may be that the templates for header1
and header2 are exeecuted "at once" in a concurrent xslt implementation,
but clearly (or not?) the results of each template exeution have to be
attatched to the result tree at different points.

It would help if you said what output you need from your sample input.

If you only want to process at most one header you could do

<xsl:apply-templates select="(header1 | header2)[1]"/>

but that processes one and ignores the other, which doesn't seem to
match the description of your desired outcome.

David
 
Reply With Quote
 
 
 
 
Joris Gillis
Guest
Posts: n/a
 
      12-03-2004
> Hello,
>
> I am creating an XSL that is going to create a report from XML we
> recieve from another system. The XML would look like:
>
> <report>
> <page>
> <header1>
> <data1>asdf</data1>
> <data2>fdas</data2>
> </header1>
> <header2>
> <dataA>xyz</dataA>
> <dataB>zyx</dataB>
> </header2>
> <reportSection1>
> <!-- Some Data Here -->
> </reportSection1>
> <reportSection2>
> <!-- Some More Data Here -->
> </reportSection2>
> </page>
> </report>
>
> Due to the size of the XML, I'm attempting to modularize the XSL. I
> want to pull out the data for the header into a seperate template.
> Currently I have the template as:
>
> <xsl:template match="header1 | header2">
> <!-- rest of the template -->
> </xsl:template>
>
> And I call it by:
>
> <xsl:apply-templates select="header1 | header2"/>
>
> The issue I'm having is that my XSL is being executed twice, once for
> each node (header1 and header2) rather than going thru both nodes at
> once. The goal is to go thru both nodes at once. Any assistance
> would be appreciated.
>


Hi,

I think - but could be wrong - that you are in fact looking for a template you can call instead of apply.

<xsl:template name="headers">
<!-- rest of the template -->
</xsl:template>

And call it by:

<xsl:call-template name="headers"/>

regards,

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
 
Reply With Quote
 
Morris M. Keesan
Guest
Posts: n/a
 
      12-03-2004
On 2 Dec 2004 13:09:39 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) (Michael) wrote:
>Hello,
>
>I am creating an XSL that is going to create a report from XML we
>recieve from another system. The XML would look like:
>
><report>
> <page>
> <header1>
> <data1>asdf</data1>
> <data2>fdas</data2>
> </header1>
> <header2>
> <dataA>xyz</dataA>
> <dataB>zyx</dataB>
> </header2>

....
></report>
>
>Due to the size of the XML, I'm attempting to modularize the XSL. I
>want to pull out the data for the header into a seperate template.
>Currently I have the template as:
>
><xsl:template match="header1 | header2">
> <!-- rest of the template -->
></xsl:template>
>
>And I call it by:
>
><xsl:apply-templates select="header1 | header2"/>
>
>The issue I'm having is that my XSL is being executed twice, once for
>each node (header1 and header2) rather than going thru both nodes at
>once. The goal is to go thru both nodes at once. Any assistance
>would be appreciated.


If you want to process both nodes at once, and process the header in a
separate template, why not call a named template?

<xsl:call-template name="header"/>

<xsl:template name="header">
<element><xsl:value-of select="header1/data1"/></element>
<another-element><xsl:value-of select="header2/dataB"/>
</another-element>
...
</xsl:template>
--
Morris M. Keesan -- (E-Mail Removed)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a variable to tell xsl:for-each which nodes to select cosmo XML 0 10-04-2008 06:14 AM
Newbie: Only select certain nodes in an xsl:template match David Cater XML 6 05-31-2007 06:04 AM
Dataset Question - Odd results with single xml nodes vs multiple nodes th3dude ASP .Net 0 01-03-2007 03:24 PM
XSL select emplty nodes ree32@hotmail.com XML 2 06-28-2005 10:33 PM
Using Select with multiple separate nodes in XSL RanDeep XML 2 09-26-2003 04:34 PM



Advertisments