This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: XSL Template Match using z:row attributes
- From: "Michael McCarty" <mccarty at onebox dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 12 Dec 2001 15:43:58 -0800
- Subject: RE: [xsl] XSL Template Match using z:row attributes
- Reply-to: xsl-list at lists dot mulberrytech dot com
Thanks Tom. I learned a bit more already. However, I still can't get
it to work. I understand recursion, but maybe not in XSL.
Here's my modified xsl:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<HTML>
<BODY topmargin="0" leftmargin="0">
<xsl:apply-templates select="/xml/rs:data/z:row"/>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="../z:row[(@LEVEL=current()/@LEVEL + 1) and (@PARENTCATEGORYID
= current()/@CATEGORYID)">
<div class="clsItem">
<span class="clsSpace" type="img"><span class="clsCollapse">+</span></span><span
class="clsLabel" type="label">
<xsl:attribute name="id"><xsl:value-of select="@CATEGORYID"/></xsl:attribute>
<xsl:attribute name="parentid"><xsl:value-of
select="@PARENTCATEGORYID"/></xsl:attribute>
<xsl:attribute name="title"><xsl:value-of select="@CATEGORYNAME"/></xsl:attribute>
<xsl:value-of select="@CATEGORYNAME"/>
</span>
<div>
<xsl:apply-templates select="../z:row[(@LEVEL=current()/@LEVEL
+ 1) and (@PARENTCATEGORYID = current()/@CATEGORYID)"/>
</div>
</div>
</xsl:template>
</xsl:stylesheet>
Here's the input (I trimed it down a bit):
<?xml-stylesheet type="text/xsl" href="CategoryTree.xsl" ?>
<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<rs:data>
<z:row LEVEL='1' CATEGORYNAME='Product 1' CATEGORYID='1' PARENTCATEGORYID='0'
CHILDSORTORDER='10'/>
<z:row LEVEL='2' CATEGORYNAME='Department A' CATEGORYID='2' PARENTCATEGORYID='1'
CHILDSORTORDER='20'/>
<z:row LEVEL='2' CATEGORYNAME='Department B' CATEGORYID='3' PARENTCATEGORYID='1'
CHILDSORTORDER='30'/>
<z:row LEVEL='3' CATEGORYNAME='Prospect' CATEGORYID='5' PARENTCATEGORYID='4'
CHILDSORTORDER='50'/>
<z:row LEVEL='4' CATEGORYNAME='Appointment' CATEGORYID='49' PARENTCATEGORYID='5'
CHILDSORTORDER='51'/>
<z:row LEVEL='4' CATEGORYNAME='Follow Up' CATEGORYID='50' PARENTCATEGORYID='5'
CHILDSORTORDER='52'/>
<z:row LEVEL='4' CATEGORYNAME='Invitation' CATEGORYID='51' PARENTCATEGORYID='5'
CHILDSORTORDER='53'/>
</rs:data>
</xml>
The output I get now is:
+
Just one + sign....? I assume that's the text() portion.... I greatly
apprecaite all you help. Thank you,
Michael =:-)
---- TSchutzerWeissmann@uk.imshealth.com wrote:
> Michael wrote:
>
> >What I am getting is this:
> >
> >+ Product 1
> >+ Product 2
> >
> >It appears that I get the LEVEL='1', but not the remaining. I wonder
> >if there's a way around 'hard coding' the LEVEL's in case I have more
> >than 4 or 5..?? I know it would be easier if my XML was is a different
> >format, but I'm forced to use the MS ADO export format. Thank you,
> in
> >advance, for your help.
>
> Hi Michael,
>
> the problem here is something like this: your input isn't nested, and
> you
> want to nest it according to a LEVEL attribute.
> There are three problems with your approach.
>
> 1. You're doing the same thing in 5 different templates. Try recursion
> instead, then you don't need to worry about how many levels you have.
>
>
> 2. The location paths in your <xsl:apply-templates>.
> You use paths fine when you select attributes, so I assume you're
> using the
> full path (xml/rs:data/z:row) here because you want to get up out of
> your
> current context (a qualified z:row).
> To make your paths work, either use /xml/rs:data/z:row - the "/" will
> get
> you back to the document node, or use ../z:row[@LEVEL=2]- in longhand
> that's
> parent::node()/z:row[@LEVEL=2]. It's just like file directories.
>
> BUT: it still won't work...
> 3. Matching children with parents.
> To get the nesting right you have to put the right children with the
> right
> parents. In your input you have CATEGORYID and PARENTCATEGORYID. A
> revised
> path, still using your approach would be
> "../z:row[(@LEVEL=2) and (@PARENTCATEGORYID =
> current()/@CATEGORYID)"
> or even
> "../z:row[(@LEVEL=current()/@LEVEL + 1) and (@PARENTCATEGORYID
> =
> current()/@CATEGORYID)"
> You need current() not . because inside a predicate expression . is
> the node
> being evaluated, not the node matched by the current template.
>
> Only recurse...
> Tom S-W
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
>
__________________________________________________
FREE voicemail, email, and fax...all in one place.
Sign Up Now! http://www.onebox.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list