XSL Attribute

Pagina: 1
Acties:

  • kingpaddo
  • Registratie: Augustus 2001
  • Laatst online: 09-08 09:51
Zit met een klein probleempje. Ben bezig om voor het eerst te proggen in XML, maar ik kom daar nog niet helemaal uit.

Ik heb als XML deze file:

<?xml version="1.0" encoding="ISO8859-1" ?>
<DOCUMENT>
<section name="TEST1">
<document href="document.asp?Id=1">Document 1</document>
<document href="document.asp?Id=2">Document 2</document>
</section>

<section name="TEST2">
<document href="document.asp?Id=3">Test 2 document 1</document>
<document href="document.asp?Id=4">Document 2</document>
</section>
</DOCUMENT>

Nu wil ik in dit geval alleen de gegevens van section met name'TEST' selecteren. En over die onderliggende 'document'
loopen.

De XSL file die ik tot nu toe heb is dit:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<body>
<table border="2" bgcolor="yellow">
<tr>
<th>Document</th>
</tr>
<xsl:for-each select="DOCUMENT/section">
<tr>
<td><xsl:value-of select="document"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


Dit werkt dus niet, kan iemand mij verder opweg helpen ? ;(

MSI KT3 Ultra ARU; Athlon XP 2100+; 2x 512 MB PC-333 Samsung;Club3d ATI Radeon 8500 PRO;2 x Maxtor 60GB Liquid Bearing; 3Com 10/100;


Verwijderd

je hebt nu xsl:for-each terwijl je VEEL beter xsl:template kan gebruiken, dan kan je namelijk doen:

<xsl:template match="Section/[@name = 'TEST']">Hebbes</xsl:template>

en dan werkt het :)

  • kingpaddo
  • Registratie: Augustus 2001
  • Laatst online: 09-08 09:51
<?xml version="1.0" encoding="ISO8859-1" ?>
<DOCUMENT>
<section name="TEST1">
<document href="document.asp?Id=1">Document 1</document>
<document href="document.asp?Id=2">Document 2</document>
</section>

<section name="TEST2">
<document href="document.asp?Id=3">Test 2 document 1</document>
<document href="document.asp?Id=4">Test 2 document 2</document>
</section>
</DOCUMENT>


<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="section[@name = 'TEST1']">
<td><xsl:value-of select="document"/></td>
</xsl:template>
</xsl:stylesheet>

Als ik nu in de XSL het volgende heb geplaatst krijg ik geen output. En hoe kan beide gegevens in 'TEST' uitschrijven ? Dus document 1 en document 2.

Er zal toch iets van een 'loop' overheen moeten ?!?

MSI KT3 Ultra ARU; Athlon XP 2100+; 2x 512 MB PC-333 Samsung;Club3d ATI Radeon 8500 PRO;2 x Maxtor 60GB Liquid Bearing; 3Com 10/100;


Verwijderd

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<body>
<table border="2" bgcolor="yellow">
<tr>
<th>Document</th>
</tr>
<tr>
<xsl:apply-templates />
</tr>
</table>
</body>
</html>
</xsl:template>

<xsl:template match="document">
<td><xsl:value-of select="."/></td>
<xsl:apply-templates />

</xsl:template>

<xsl:template match="section[@name = 'TEST1']">
<td><xsl:value-of select="document"/></td>
</xsl:template>
</xsl:stylesheet>

Of zo, maar het is handig als je eerst eens een tutorial (vanaf www.xfront.com) doorleest, zodat je weet wat je tikt :).