[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: template matches more than once

Subject: Re: template matches more than once
From: "Rudolf P. Weinmann" <rudolf.weinmann@xxxxxx>
Date: Thu, 3 Aug 2000 23:00:20 +0200
rudolf template
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.