|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Newbie question - dynamic filter on attribute values
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








