| Subject: Newbie question - dynamic filter on attribute values From: "Super, Karen" <Karen.Super@xxxxxxxxxxxxx> Date: Wed, 16 Feb 2000 11:58:42 -0600 | 
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 | 
|---|
| 
 | 
| <- Previous | Index | Next -> | 
|---|---|---|
| RE: Example for XML + XSL -> .fo ?, Pawson, David | Thread | RE: Newbie question - dynamic filte, Kay Michael | 
| Re: Example for XML + XSL -> .fo ?, John E. Simpson | Date | How To Include external XSL files i, Jim Garrett | 
| Month |