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 problem

Status
Not open for further replies.

intrex

IS-IT--Management
Apr 14, 2002
70
US
I am having a problem making an xslt template to pase a small xml file I have.

I am passing the xslt file one parameter. I want to use this parameter to match a node that has the parameter in it then loop through its children.

the xml file looks like this.

<HEADER>
<LINK name="Education">
<TITLE>HighSchool</TITLE>
<URL>/Intrests.aspx</URL>
<TITLE>Bachelors</TITLE>
<URL>/Projects.aspx</URL>
<TITLE>Masters</TITLE>
<URL>/Projects.aspx</URL>
<TITLE>Certifications</TITLE>
<URL>/Projects.aspx</URL>
</LINK>
<LINK name="Home"></LINK>
<LINK name="Interests"></LINK>
<LINK name="Contact"></LINK>
<LINK name="Project"></LINK>
<LINK name="Work"></LINK>
<LINK name="About Site"></LINK>
</HEADER>

I want to use my passed in parameter to match the name attribute of the link node and loop through the TITLE and URL elements within that node.

I was trying something like this without much luck.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=" version="1.0">
<xsl:template match="/">
<!-- BUILD Left Menu Bar -->

<xsl:param name="LINK" select="Education"></xsl:param>
<xsl:for-each select="//HEADER/LINK/@name">
<xsl:if test="@name=$LINK">
<xsl:for-each select="//HEADER/LINK/TITLE">
<a>
<xsl:attribute name="HREF">test<xsl:value-of select="TITLE"/>test</xsl:attribute>
<xsl:value-of select="@name" />

</a>
</xsl:for-each>
</xsl:if>
</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

I know the loops above don't exactly make sense right now because I have been changing them so much but I can't get anything I try to work. I am setting the parameter "LINK" above to Education just for testing purposes.

Any help would be much apreciated.
 
Not entirely sure what you are after and your XML is not very semantically organised, but try this for some ideas:
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
  <xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="[URL unfurl="true"]http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"[/URL] omit-xml-declaration="yes"/>
  <xsl:param name="LINK" select="'Education'"/>
  <xsl:template match="/">
    <html>
      <head>
        <title>My page</title>
      </head>
      <body>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="HEADER">
    <div id="leftmenu">
      <xsl:apply-templates select="LINK[@name = $LINK]"/>
    </div>
  </xsl:template>
  <xsl:template match="LINK">
    <ul>
      <xsl:apply-templates select="TITLE"/>
    </ul>
  </xsl:template>
  <xsl:template match="TITLE">
    <li>
      <a href="{../@name}/{.}{following-sibling::node()[1]}">
        <xsl:value-of select="../@name"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="."/>
        <xsl:value-of select="following-sibling::node()[1]"/>
      </a>
    </li>
  </xsl:template>
</xsl:stylesheet>

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top