Thread: xsl question
View Single Post
  #1 (permalink)  
Old September 13th, 2005, 06:58 PM
bluisana bluisana is offline
Registered User
 
Join Date: Sep 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default xsl question

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="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">


    <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.

Is there a better way to do this istead of using 2 loops?

Any help would be much apreciated.


Reply With Quote