![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - How to select a custom set of nodes based on their IDs? >Thread Next - Re: How to select a custom set of nodes based on their IDs? Re: How to select a custom set of nodes based on their IDs?To: NULL Date: 8/14/2007 1:49:00 PM
Joannes Vermorel wrote:
> I have a XML document that looks like
>
> <foo>
> <bar id="001" ... />
> <bar id="002" ... />
> ...
> </foo>
>
> I have a XSL template to represent a <bar/> node. I would like to be
> able to select a list of explicit IDs like
> select{001; 007; 012}
> in a compact manner (and to apply the <bar/> template each selected
> node afterward).
>
> Does anyone know a compact syntax to do that?
There is no compact syntax for that in XPath 1.0, you need e.g.
<xsl:apply-templates select="foo/bar[@id = '001' or @id = '007' or
@id = '012']"/>
With XPath 2.0 you can do
<xsl:apply-templates select="foo/bar[@id = ('001', '007', '012')]"/>
What you can do in XSLT 1.0 is store the ids in the stylesheet e.g.
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:data="http://example.com/2007/data"
exclude-result-prefixes="data"
<data:data xmlns="">
<id>001</id>
<id>007</id>
<id>012</id>
</data>
<xsl:template match="/">
<xsl:apply-templates
select="foo/bar[@id = document('')/*/data:data/id]"/>
</xsl:template>
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
