How to organize correctlly this example XSL transformation?

I have xml input file:

<Event>
   <Result id='1'></Result>
   <Result id='2'></Result>
   <Result id='3'></Result>
   <Result id='4'></Result>
   <EventData>
      <Data id='1'></Data>
      <Data id='2'></Data>
      <Data id='3'></Data>
      <Data id='4'></Data>
   </EventData>
</Event>

The transformed HTML file should shows:

<h2>Even:</h2>
Bla bla
<h2> EventData:</h2>
 <ul>
   <li>Data (1) : Result(1) </li>                
    <li>Data (2) : Result(2) </li>
...
<ul>

   
koleto115Asked:
Who is Participating?
 
Geert BormansConnect With a Mentor Information ArchitectCommented:
Well, it would provide you with nicer code anyway
(200 results should not be a problem)
Here is the example, the previous is easier to understand,
the new one is what I would use in a production environment
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:key name="res" match="Event/Result" use="@id"/>
    <xsl:template match="Event">
        <html>
            <body>
                <h2>Event:</h2>
                <p>blabla</p>
                <h2>EventData:</h2>
                <ul>
                    <xsl:apply-templates select="EventData/Data"/>
                </ul>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="Data">
        <li>
            <xsl:value-of select="."/>
            <xsl:text> : </xsl:text>
            <xsl:value-of select="key('res', @id)"/>
        </li>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
Geert BormansConnect With a Mentor Information ArchitectCommented:
This could work
If the file gets big, I recommend indexing, using a key
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="Event">
    <html>
        <body>
            <h2>Event:</h2>
            <p>blabla</p>
            <h2>EventData:</h2>
            <ul>
                <xsl:apply-templates select="EventData/Data"/>
            </ul>
        </body>
    </html>
</xsl:template>
    <xsl:template match="Data">
        <li>
            <xsl:value-of select="."/>
        <xsl:text> : </xsl:text>
        <xsl:value-of select="ancestor::Event/Result[@id = current()/@id]"/>
        </li>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
koleto115Author Commented:
Thanks.

There should by not more then 200 result nodes. Do I still have to use key?
If so where can I find an example?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.