Subject: Re: template matches more than once From: "Rudolf P. Weinmann" <rudolf.weinmann@xxxxxx> Date: Thu, 3 Aug 2000 23:00:20 +0200 |
Maybe I misunderstood your problem. In your xml-file you have two elements with item_ParentID="2" and therefore your template gets executed twice. Rudolf P. Weinmann Innovation Process Technology Inc Switzerland ----- Original Message ----- From: "Tom Power" <TomP@xxxxxxxxxxxxxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxx> Sent: Thursday, August 03, 2000 5:27 AM Subject: template matches more than once > > Hello, > > > > In a nutshell, I have a template being applied more than it should. I have > > attached the XSL, XML and an ASP page at the end of this message. You need > > to have MSXML3.dll available from Microsoft. > > > > I know that I could use recursion, but this question is more about > > understanding why the XSL processor is doing what it is doing - is my XSL > > is correct? > > > > If you look at the XML structure attached, it describes a simple menu > > structure: > > MyMenu (id=1, parent=-1) > > -File (id=2, parent=1) > > -Save (id=3, **parent=2**) > > -Documents (id=4, **parent=2**) > > -Doc1 > > Doc1.1 > > -Doc2 > > -Edit (parent=1) > > -About Us (parent=1) > > -Register > > > > An item links to a parent via item_ParentID. The simple xsl below attempts > > to extract all items where item_ParentID=2, which should match on the item > > elements where item_Text='Save', and 'Documents'. It does this match, but > > it does it twice. > > > > Furthermore, if I change the XSL to match where item_ParentID=1, expecting > > to get back 'File', 'Edit' and 'About Us' - it works, i.e. it only matches > > once for each element. > > > > It appears the matching has mixed results, depending on where in the xml > > tree the first match is made. #*&$*#&$Please help!! > > > > Thank you in advance, > > > > Tom. > > > > **HERE IS THE XSL - Save to C:\Temp\menu.xsl > > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > > version="1.0"> > > <xsl:template match="/"> > > <HTML> > > <HEAD></HEAD> > > <BODY> > > <p>Select clause = file://item - i.e. select all > > 'item' elements in tree regardless of ancestry.</p> > > <xsl:apply-templates select="//item" /> > > </BODY> > > </HTML> > > </xsl:template> > > > > <xsl:template match="item[@item_ParentID=2]"> > > <!--why is this template called twice --> > > <p> > > <xsl:value-of select="@item_text" /> > > </p> > > </xsl:template> > > > > </xsl:stylesheet> > > > > **HERE IS THE XML** - save to C:\TEMP\menu.xml > > <menu item_id="1" item_OrdinalPos="1" item_ParentID="-1" item_SubItems="3" > > item_text="my menu" item_href=""> > > <item item_id="2" item_OrdinalPos="1" item_ParentID="1" item_SubItems="2" > > item_text="File" item_href=""> > > <item item_id="4" item_OrdinalPos="1" item_ParentID="2" item_SubItems="0" > > item_text="Save" item_href=""></item> > > <item item_id="5" item_OrdinalPos="2" item_ParentID="2" item_SubItems="2" > > item_text="Documents" item_href=""> > > <item item_id="6" item_OrdinalPos="1" item_ParentID="5" item_SubItems="1" > > item_text="Doc1" item_href=""> > > <item item_id="10" item_OrdinalPos="1" item_ParentID="6" item_SubItems="0" > > item_text="Doc1.1" item_href=""></item></item> > > <item item_id="7" item_OrdinalPos="2" item_ParentID="5" item_SubItems="0" > > item_text="Doc2" item_href=""></item></item></item> > > <item item_id="3" item_OrdinalPos="2" item_ParentID="1" item_SubItems="0" > > item_text="Edit" item_href=""></item> > > <item item_id="8" item_OrdinalPos="3" item_ParentID="1" item_SubItems="1" > > item_text="About Us" item_href=""> > > <item item_id="9" item_OrdinalPos="1" item_ParentID="8" item_SubItems="0" > > item_text="Register" item_href=""></item></item></menu> > > > > > > > > **HERE IS THE ASP page > > Note, call the page with a querystring of ?debug=True to just display the > > XML file above. > > > > <%@ Language=VBScript%> > > <% > > option explicit%> > > <% > > dim sHTML > > dim oxsl > > dim oxml > > dim doDebug > > dim whichStyle > > > > doDebug=Request.QueryString("debug") > > doDebug=cbool(doDebug) > > > > set oXML=server.CreateObject("MSXML2.DOMDocument.3.0") > > set oXSL=server.Createobject("MSXML2.DOMDocument.3.0") > > oXML.async=false > > oXML.load "C:\Temp\menu.xml" > > oXSL.load "C:\Temp\menu.xsl" > > if doDebug then > > Response.ContentType="text/xml" > > oxml.save Response > > else > > sHTML=oXML.transformnode(oXSL) > > Response.ContentType="text/html" > > Response.Write sHTML > > end if > > Response.end > > %> > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: template matches more than once, Jeni Tennison | Thread | Re: DTP DTD?, Stephan Albers |
RE: Javascript : from xsl to xml, Chris Bayes | Date | RE: <xsl:stylesheet xmlns..., Joshua Allen |
Month |