This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: XSL Template Match using z:row attributes


Thanks, that did it.  However, it's not producing what I expected.  Sorry
for my ignorance, but here's what I'd like to do:

I'm trying to build a heirarchy based on the @LEVEL attrbiute
in my input XML.

So, if my input xml is:

<rs:data>
<z:row LEVEL='1' CATEGORYNAME='Product 1' CATEGORYID='1' PARENTID='0'
/>
<z:row LEVEL='2' CATEGORYNAME='Department A' CATEGORYID='2'
PARENTID='1' />
<z:row LEVEL='2' CATEGORYNAME='Department B' CATEGORYID='3'
PARENTID='1' />
<z:row LEVEL='3' CATEGORYNAME='Prospect' CATEGORYID='5' PARENTID='4'
/>
<z:row LEVEL='4' CATEGORYNAME='Appointment' CATEGORYID='49'
PARENTID='5' />
</rs:data>

I want to create output that's something like this:

<div level=1>
    Product 1
    <div level=2>
        Department A
    </div>
    <div level=2>
        Department B
        <div level=3>
            Prospect
            <div level=4>
                Appointment
            </div>
        </div>
    </div>
</div>

I realize that this would be easier if my imput data was already in a
traditional hierarchical format, but I'm using MS ADO XML output
format.

Any more ideas??

Thanks,

Mike =:-)

---- "Ivan Pedruzzi" <ivan@exceloncorp.com> wrote:
> 
> Hi Michael,
> 
> with this small change works as you expected.
> 
> <xsl:apply-templates select="../z:row[(@LEVEL=current()/@LEVEL + 1)
> and
> (@PARENTID=current()/@CATID) and not(current()=preceding-sibling::*)]"/>
> 
> Ivan Pedruzzi
> eXcelon Corporation
> http://www.stylusstudio.com
> 
> 
> 
> > -----Original Message-----
> > From: owner-xsl-list@lists.mulberrytech.com 
> > [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of 
> > Michael McCarty
> > Sent: Wednesday, December 12, 2001 11:22 PM
> > To: xsl-list@lists.mulberrytech.com
> > Subject: RE: [xsl] XSL Template Match using z:row attributes
> > 
> > 
> > Ok, you might need to ignore my previous reply.  I've been 
> > playing with the XSL and (with the help of that Xselerator 
> > tool) I think I understand better, but not completly.
> > 
> > My problem is that I'm getting duplicate output.  The XML 
> > (trimmed) is:
> > 
> > <?xml-stylesheet type="text/xsl" href="CategoryTree2.xsl" ?> 
> > <xml xmlns:rs='urn:schemas-microsoft-com:rowset'
> > 	 xmlns:z='#RowsetSchema'>
> > <rs:data>
> > 	<z:row LEVEL='1' CATNAME='Level 1' CATID='1' PARENTID='0'
> />
> > 	<z:row LEVEL='2' CATNAME='Level 2' CATID='3' PARENTID='1'
> />
> > 	<z:row LEVEL='2' CATNAME='Level 2' CATID='4' PARENTID='1'
> />
> > 	<z:row LEVEL='3' CATNAME='Level 3' CATID='5' PARENTID='4'
> />
> > 	<z:row LEVEL='3' CATNAME='Level 3' CATID='6' PARENTID='4'
> />
> > 	<z:row LEVEL='1' CATNAME='Level 1' CATID='21' PARENTID='0'
> />
> > 	<z:row LEVEL='2' CATNAME='Level 2' CATID='22' 
> > PARENTID='21' /> </rs:data> </xml>
> > 
> > The XSL is:
> > 
> > <?xml version='1.0'?>
> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> 
> > 		xmlns:rs='urn:schemas-microsoft-com:rowset'
> > 		xmlns:z='#RowsetSchema'	version="1.0">
> > 
> > <xsl:template match="/">
> > 	<HTML>
> > 	<BODY topmargin="0" leftmargin="0">
> > 	<xsl:apply-templates select="/xml/rs:data"/>
> > 	</BODY>
> > 	</HTML>
> > </xsl:template>
> > 
> > <xsl:template match="z:row">
> > <div class="clsItem">
> > 	CatId_<xsl:value-of select="@CATID"/> - 
> > 	<b><xsl:value-of select="@CATNAME"/></b> - 
> > 	Parent_<xsl:value-of select="@PARENTID"/>
> >   <div id="container">
> > 	<xsl:apply-templates select="../z:row[(@LEVEL=current()/@LEVEL
> > + 1) and (@PARENTID=current()/@CATID)]"/>
> >   </div>
> > </div>
> > </xsl:template>
> > </xsl:stylesheet> 
> > 
> > Here's what I get:
> > 
> > CatId_1 - Level 1 - Parent_0
> > CatId_3 - Level 2 - Parent_1
> > CatId_4 - Level 2 - Parent_1
> > CatId_5 - Level 3 - Parent_4
> > CatId_6 - Level 3 - Parent_4
> > CatId_3 - Level 2 - Parent_1   <!-- duplicate -->
> > CatId_4 - Level 2 - Parent_1   <!-- duplicate -->
> > CatId_5 - Level 3 - Parent_4   <!-- duplicate -->
> > CatId_6 - Level 3 - Parent_4   <!-- duplicate -->
> > CatId_5 - Level 3 - Parent_4   <!-- duplicate -->
> > CatId_6 - Level 3 - Parent_4   <!-- duplicate -->
> > CatId_21 - Level 1 - Parent_0
> > CatId_22 - Level 2 - Parent_21
> > CatId_22 - Level 2 - Parent_21   <!-- duplicate -->
> > 
> > I think I'm going crazy learning this... =:-)
> > As always, your help is greatly appreciated.
> > 
> > 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
> > 
> > 
> 
> 
>  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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]