Select multiple nodes in XSL

Discussion in 'XML' started by Michael, Dec 2, 2004.

  1. Michael

    Michael Guest

    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
    Michael, Dec 2, 2004
    #1
    1. Advertising


  2. > <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
    David Carlisle, Dec 2, 2004
    #2
    1. Advertising

  3. Michael

    Joris Gillis Guest

    > 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-view.cgi?userid=38041)
    Ceterum censeo XML omnibus esse utendum
    Joris Gillis, Dec 3, 2004
    #3
  4. On 2 Dec 2004 13:09:39 -0800, (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 --
    Morris M. Keesan, Dec 3, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RanDeep
    Replies:
    2
    Views:
    1,601
    RanDeep
    Sep 26, 2003
  2. Replies:
    2
    Views:
    395
  3. th3dude
    Replies:
    0
    Views:
    433
    th3dude
    Jan 3, 2007
  4. David Cater
    Replies:
    6
    Views:
    1,773
    Pavel Lepin
    May 31, 2007
  5. cosmo
    Replies:
    0
    Views:
    1,425
    cosmo
    Oct 4, 2008
Loading...

Share This Page