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

Re: XSLT filter syntax advice?

Subject: Re: XSLT filter syntax advice?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 26 Nov 2009 13:01:46 +0530
Re:  XSLT filter syntax advice?
At 2009-11-25 23:04 -0500, Doug Meade wrote:
Hey folks -

I'm trying to use XSLT to transform the following XML into HTML...

<Catalog>
    <Category>
    <Name>Category A</Name>
        <Item>
        <Id>Item 1a</Id>
        <Rank>1</Rank>
        <Title><![CDATA[The Title of Item 1a]]></Title>
        <Description><![CDATA[a great description of item 1a]]></Description>
        </Item>
        <Item>
        <Id>Item 2a</Id>
        <Rank>2</Rank>
        <Title><![CDATA[The Title of Item 2a]]></Title>
        <Description><![CDATA[a great description of item 2a]]></Description>
        </Item>
    </Category>
    <Category>
    <Name>Category B</Name>
        <Item>
        <Id>Item 1b</Id>
        <Rank>5</Rank>
        <Title><![CDATA[The Title of Item 1b]]></Title>
        <Description><![CDATA[a great description of item 1b]]></Description>
        </Item>
        <Item>
        <Id>Item 2b</Id>
        <Rank>10</Rank>
        <Title><![CDATA[The Title of Item 2b]]></Title>
        <Description><![CDATA[a great description of item 2b]]></Description>
        </Item>
    </Category>
</Catalog>

I'm getting hung up on the XSLT syntax that will display all the
"Items" for a particular Category. I can list the categories - or the
Items, but listing the items in a particular category is not working
so well.

You don't show the syntax that isn't working, so it is difficult to guess where you are going wrong.


I assume I need to pass the category as a parameter, but still not
getting it quite right.

No, I'm not sure what you mean by a "parameter" as there are no functions being called.


My guess is you are using /Catalog/Category/Item to display the items ... which, of course, displays all items each time you use that address.

If this is your case, you need to instead use a relative address:

   <xsl:for-each select="/Catalog/Category">
     ...stuff for category...
     <xsl:for-each select="Item">
        ...stuff for the item within the category...
     </xsl:for-each>
   </xsl:for-each>

But, as I said, I'm only guessing what you are doing wrong.

Look for discussions of relative XPath addresses. You position yourself in the document node tree and then use relative addresses to get information that is relative hierarchically to your point. *If* your information were relative as siblings then you would need to look into grouping rather than into hierarchy, but given your example, grouping isn't what you need here.

I hope this helps.

. . . . . . . . . . Ken


-- Vote for your XML training: http://www.CraneSoftwrights.com/s/i/ Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

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-2011 All Rights Reserved.