Select multiple nodes in XSL

M

Michael

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
 
D

David Carlisle

<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
 
J

Joris Gillis

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,
 
M

Morris M. Keesan

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top