Click to See Complete Forum and Search --> : Need help with XSL


redijedi
04-28-2004, 04:41 PM
I'm having difficulty figuring out how to get this one working.

I have an xml file with the following structure:


<submenu match="/econdev/">
<item>
<text>Director Information</text>
<link>/econdev/about/director.cfm</link>
</item>
<item>
<text>Contact Us</text>
<link>/econdev/about/contact.cfm</link>
</item>
</submenu>
<submenu match="/econdev/about/">
<item>
<text>Director Information</text>
<link>/econdev/about/director.cfm</link>
</item>
<item>
<text>Contact Us</text>
<link>/econdev/about/contact.cfm</link>
</item>
</submenu>


I have it transformed with an XSL file as such: (snippet)


<xsl:if test="$curdirectory=submenu/@match">
<xsl:apply-templates select="submenu"/>
</xsl:if>


If $curdirectory matches correctly, the template is applied to both submenus even though only the first one matches?! How can I force it to only apply the template of the matching element?

Thanks sooooo much.

r3alityc0d3r
04-28-2004, 05:49 PM
I could only get it to work the way you want it by using the code this way:

Here is the XSL

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/menu/submenu">
<html>
<head>
<title>Input values</title>
</head>
<body>
<xsl:if test="match='$curdirectory'">
<xsl:apply-templates select="item"/><br/>
</xsl:if>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
[CODE]

and here is the XML:

[CODE]
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<menu>
<submenu>
<match>/econdev/</match>
<item>
<text>Director Information</text>
<link>/econdev/about/director.cfm</link>
</item>
<item>
<text>Contact Us</text>
<link>/econdev/about/contact.cfm</link>
</item>
</submenu>
<submenu>
<match>/econdev/about/</match>
<item>
<text>Director Information</text>
<link>/econdev/about/director.cfm</link>
</item>
<item>
<text>Contact Us</text>
<link>/econdev/about/contact.cfm</link>
</item>
</submenu>
</menu>


This produced the desired result. I think the test elemt matches anything that includes the $curdirectory. Since both the match elements had the curdirectory in them, it matched them both. I could not think of a way to prevent this off the top of my head so I came up with this solution. Hope this helps.

redijedi
04-28-2004, 06:47 PM
Thanks for your response. The solution you proposed won't work in the overall scheme, unfortunately I'm modifying existing code that can't be changed too much. However I was able to add an xsl:if in the submenu template that checked the match. Everything seems to work now.

Thanks!

r3alityc0d3r
04-28-2004, 06:51 PM
That one was a lil difficult. Glad you got it working though.