Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL Help 1

Status
Not open for further replies.

Gibble

Programmer
Nov 9, 2000
3
CA
I have the following XML File:

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;../XSLT/forum.xsl&quot;?>
<webboard>
<forums>
<forum id=&quot;1&quot;>
<reference name=&quot;category&quot; id=&quot;1&quot;/>
<name>XML</name>
<desc/>
</forum>
<forum id=&quot;2&quot;>
<reference name=&quot;category&quot; id=&quot;2&quot;/>
<name>Windows 9x/NT/Me/2k</name>
<desc/>
</forum>
</forums>
<categories>
<category id=&quot;1&quot;>
<name>Internet Programming</name>
<desc/>
</category>
<category id=&quot;2&quot;>
<name>Operating Systems</name>
<desc/>
</category>
</categories>
<users>
<user id=&quot;1&quot;>
<alias>Admin</alias>
<email>Admin@gibble.yi.org</email>
</user>
<user id=&quot;2&quot;>
<alias>Gibble</alias>
<email>Gibble@gibble.yi.org</email>
</user>
</users>
<threads>
<thread id=&quot;1&quot;>
<reference name=&quot;forum&quot; id=&quot;1&quot;/>
<reference name=&quot;user&quot; id=&quot;2&quot;/>
<name>What is XML?</name>
<date>11/24/2000</date>
<file>T000001.xml</file>
</thread>
<thread id=&quot;2&quot;>
<reference name=&quot;forum&quot; id=&quot;1&quot;/>
<reference name=&quot;user&quot; id=&quot;2&quot;/>
<name>What is XSL?</name>
<date>11/24/2000</date>
<file>T000002.xml</file>
</thread>
<thread id=&quot;3&quot;>
<reference name=&quot;forum&quot; id=&quot;2&quot;/>
<reference name=&quot;user&quot; id=&quot;1&quot;/>
<name>What is the difference b/w Win 9x and Win Me</name>
<date>11/24/2000</date>
<file>T000003.xml</file>
</thread>
</threads>
</webboard>


And I need to transform it with the following XSL file:

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot; <xsl:template match=&quot;/&quot;>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match=&quot;webboard&quot;>
<xsl:apply-templates select=&quot;categories&quot;/>
</xsl:template>

<xsl:template match=&quot;categories&quot;>
<xsl:apply-templates select=&quot;category&quot;/>
</xsl:template>

<xsl:template match=&quot;category&quot;>
<div class=&quot;CategoryName&quot;>
<xsl:for-each select=&quot;//forums/forum/reference/@id&quot;>
<xsl:value-of select=&quot;.&quot;/>
</xsl:for-each>
</div>
</xsl:template>

<xsl:template match=&quot;forums&quot;>
<xsl:apply-templates select=&quot;forum&quot;/>
</xsl:template>

<xsl:template match=&quot;forum&quot;>
<div class=&quot;ForumName&quot;><xsl:value-of select=&quot;name&quot;/></div>
</xsl:template>
</xsl:stylesheet>


The problem is in the XSL here:
<xsl:template match=&quot;category&quot;>
<div class=&quot;CategoryName&quot;>
<xsl:for-each select=&quot;//forums/forum/reference/@id&quot;>
<xsl:value-of select=&quot;.&quot;/>
</xsl:for-each>
</div>
</xsl:template>

I need the for-each to select all of the forums that have the id referencing the category and I can't figure out how to select that I NEED help!!

TIA
 
hello, Gibble.

I guess that you must type:

<xsl:template match=&quot;category&quot;>
<div class=&quot;CategoryName&quot;>
<xsl:for-each select=&quot;//forums/forum&quot;>
<xsl:value-of select=&quot;reference/@id&quot;/>
</xsl:for-each>
</div>
</xsl:template>

Best regards.

Avator
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top