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

Newbie question - dynamic filter on attribute values

Subject: Newbie question - dynamic filter on attribute values
From: "Super, Karen" <Karen.Super@xxxxxxxxxxxxx>
Date: Wed, 16 Feb 2000 11:58:42 -0600
xsl filter by attribute
I apologize if this has already been discussed, but I am new to XML and XSLT
and have been reading some of the posts and haven't seem to come across my
situation.  I have data similar to the following:

<book attr="1">
    <title attr="10">This is the title</title>
    <chap attr="20">
        <title attr="25">Chapter title 1</title>
        <para attr="26">This is a paragraph in the first chapter</para>
    </chap>        
    <chap attr="20">
        <title attr="25">Chapter title 2</title>
        <para attr="26">This is a paragraph in the second chapter</para>
    </chap>        
</book>

I would like to initially filter out my document based on the attr values.
I will be receiving an array of numbers that correspond to the numbers in
attr.  I only want those elements that match these numbers.  For example, if
I receive 25 and 26, I only want to work with the <title> and <para>
elements.  This array of numbers that I will be receiving will vary from
request to request, meaning I may get a request for only 10 and 25, or just
26.  I would like to somehow dynamically combine this logic into the
following stylesheet, but I am not sure how to do it.

<xsl:template match="chap/title">
    <FormatScope>
	 <Format>
	     <ESC/>TB
		 </Format>
		 <Content>
		     <xsl:apply-templates/>
		 </Content>
		 <Format>
		     <ESC/>TE
		 </Format>
    </FormatScope>
</xsl:template>

<xsl:template match="para">
    <FormatScope>
        <Format>
            <ESC/>PB
        </Format>
        <Content>
            <xsl:apply-templates/>
        </Content>
        <Format>
            <ESC/>PE
        </Format>
    </FormatScope>
</xsl:template>
  
The resulting XML would be:

<FormatScope>
    <Format>
        <ESC/>TB
    </Format>
    <Content>Chapter title 1</Content>
    <Format>
        <ESC/>TE
    </Format>
</FormatScope>

<FormatScope>
    <Format>
        <ESC/>PB
    </Format>
    <Content>This is a paragraph in the first chapter</Content>
    <Format>
        <ESC/>PE
    </Format>
</FormatScope>

<FormatScope>
    <Format>
        <ESC/>TB
    </Format>
    <Content>Chapter title 2</Content>
    <Format>
        <ESC/>TE
    </Format>
</FormatScope>

<FormatScope>
    <Format>
        <ESC/>PB
    </Format>
    <Content>This is a paragraph in the second chapter</Content>
    <Format>
        <ESC/>PE
    </Format>
</FormatScope>


Using XSLT, is there a way to do what I am trying to accomplish?  Any
suggestions are greatly appreciated.

Thanks,
Karen


 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.