views:

68

answers:

1

HI!

My XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<Dokument>
     <Skupina id="3">
      <Naziv_skupine>RAZSTAVNI PROSTOR</Naziv_skupine>
        <Dvorana id="295">
        <Naziv_dvorane>DVORANA  C</Naziv_dvorane>
         <Postavka id="41">
          <Artikel>1105</Artikel>
         </Postavka>
        </Dvorana>

        <Dvorana id="281">
        <Naziv_dvorane>DVORANA A</Naziv_dvorane>
         <Postavka id="41">
          <Artikel>1102</Artikel>
         </Postavka>
        </Dvorana>
     </Skupina>


     <Skupina id="86">
      <Naziv_skupine>UPORABNINA PROSTORA, TEHNIČNE OPREME IN OSEBJA</Naziv_skupine>
        <Dvorana id="295">
        <Naziv_dvorane>DVORANA  C</Naziv_dvorane>
         <Postavka id="41">
          <Artikel>2100</Artikel>
         </Postavka>
        </Dvorana>
     </Skupina>


</Dokument>

My XSLT:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <table border="1">

    <xsl:for-each select="Dokument/Skupina">
    <tr>
        <td align="left" colspan="7" valign="top"><xsl:value-of select="Naziv_skupine"/></td>
        </tr>

        <xsl:for-each select="/Dokument/Skupina/Dvorana">
      <tr>
        <td align="left" colspan="7" valign="top"><xsl:value-of select="Naziv_dvorane"/></td>
      </tr>
     <xsl:for-each select="/Dokument/Skupina/Dvorana/Postavka">
       <tr>
         <td valign="top"><xsl:value-of select="Artikel"/></td>      
       </tr>
     </xsl:for-each>
     </xsl:for-each>
     </xsl:for-each>

    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

Result:

RAZSTAVNI PROSTOR
  DVORANA C
    1105
    1102
    2100
  DVORANA A
    1105
    1102
    2100
  DVORANA C
    1105
    1102
    2100
UPORABNINA PROSTORA, TEHNIČNE OPREME IN OSEBJA
  DVORANA C
    1105
    1102
    2100
  DVORANA A
    1105
    1102
    2100
  DVORANA C
    1105
    1102
    2100

But I want the result like this:

RAZSTAVNI PROSTOR
  DVORANA C
    1105
  DVORANA A
    1102
UPORABNINA PROSTORA, TEHNIČNE OPREME IN OSEBJA
  DVORANA C
   2100

Where do I get wrong?

Thanks!

Tom

+1  A: 

In the second for-each, try changing this path

/Dokument/Skupina/Dvorana/Postavka

to

./Postavka

You want to continue the second for-each loop at the node the first one is pointing at. What you're doing is re-selecting all nodes from the root, since you specify /Dokument/....

csl
Thanks, that's working
Tom