R
Ruthless
Hello.
I've got a simple XML:
<?xml version="1.0" encoding="iso-8859-2"?>
<?xml-stylesheet type="text/xsl" href="4.xsl"?>
<struct>
<node level="1" no="1">
<node level="2" no="2" />
<node level="2" no="3" />
<node level="2" no="4" />
</node>
<node level="1" no="5">
<node level="2" no="6" />
<node level="2" no="7" />
<node level="2" no="8" />
</node>
</struct>
and i want to display all the levels starting from 1 to 2
I've got my xslt sth like this:
<?xml version="1.0" encoding="ISO-8859-2" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput method="html"/>
<xsl:template match="/">
<html>
<body>
<table align="center" border="1">
<tr>
<th>Name</th><th>No.</th><th>Level</th>
</tr>
<xsl:for-each select="//node">
<xsl:sort select="@level"/>
<xsl:if test="@level='1'">
<tr>
<td align="center"><xsl:value-of select="name()"/></td>
<td><xsl:value-of select="@no"/></td>
<td><xsl:value-of select="@level"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
<!-- now goes level 2-->
<table align="center" border="1">
<tr>
<th>Name</th><th>No.</th><th>Level</th>
</tr>
<xsl:for-each select="//node">
<xsl:sort select="@level"/>
<xsl:if test="@level='2'">
<tr>
<td align="center"><xsl:value-of select="name()"/></td>
<td><xsl:value-of select="@no"/></td>
<td><xsl:value-of select="@level"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
It works fine but it's useless when there would be more then 2 levels - how
can i loop this template to go through all the levels - each level has a new
table(just like above)
and second thing how can i count node with e.g. attributes level="2"?
I've tried sth like this:
<xsl:template match="/">
<xsl:variable name="ile" select="count(//node@level='2')" />
</xsl:template>
and then:
<b><xsl:value-of select="$ile"/></b>
but it's wrong and i've got warning msg.
thanks in advance
greetings R
I've got a simple XML:
<?xml version="1.0" encoding="iso-8859-2"?>
<?xml-stylesheet type="text/xsl" href="4.xsl"?>
<struct>
<node level="1" no="1">
<node level="2" no="2" />
<node level="2" no="3" />
<node level="2" no="4" />
</node>
<node level="1" no="5">
<node level="2" no="6" />
<node level="2" no="7" />
<node level="2" no="8" />
</node>
</struct>
and i want to display all the levels starting from 1 to 2
I've got my xslt sth like this:
<?xml version="1.0" encoding="ISO-8859-2" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput method="html"/>
<xsl:template match="/">
<html>
<body>
<table align="center" border="1">
<tr>
<th>Name</th><th>No.</th><th>Level</th>
</tr>
<xsl:for-each select="//node">
<xsl:sort select="@level"/>
<xsl:if test="@level='1'">
<tr>
<td align="center"><xsl:value-of select="name()"/></td>
<td><xsl:value-of select="@no"/></td>
<td><xsl:value-of select="@level"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
<!-- now goes level 2-->
<table align="center" border="1">
<tr>
<th>Name</th><th>No.</th><th>Level</th>
</tr>
<xsl:for-each select="//node">
<xsl:sort select="@level"/>
<xsl:if test="@level='2'">
<tr>
<td align="center"><xsl:value-of select="name()"/></td>
<td><xsl:value-of select="@no"/></td>
<td><xsl:value-of select="@level"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
It works fine but it's useless when there would be more then 2 levels - how
can i loop this template to go through all the levels - each level has a new
table(just like above)
and second thing how can i count node with e.g. attributes level="2"?
I've tried sth like this:
<xsl:template match="/">
<xsl:variable name="ile" select="count(//node@level='2')" />
</xsl:template>
and then:
<b><xsl:value-of select="$ile"/></b>
but it's wrong and i've got warning msg.
thanks in advance
greetings R