[quoted text, click to view] "Luke Vogel" <not@_real_address> wrote in message news:eQP4csImEHA.712@TK2MSFTNGP09.phx.gbl...
> <category>Computers</category>
> <image>images/comp-MSVB_SBS.jpg</image>
> </product>
>
> I need to be able to extract only books that belong to a specific category (in the example above 'Computers')
>
> I've been looking at the <xsl:if test="expression"> construct, but I cant figure out the syntax for the test expression.
> I keep getting "invalid token" errors, or something about being part of a dataset ...
The exact expression depends on the context node, if you are in a template matching product then
it's simply: category='Computers'
e.g.,
<xsl:template match="product" >
<xsl:if test="category='Computers'">
<!-- Do something with this product node. -->
</xsl:if>
</xsl:template>
Notice that since the test attribute is delimited in double quotes, the text literals within the TestExpr
should be delimited in single quotes.
If this is all your template is doing, however, you could make it match more specifically and do
w/o an <xsl:if> altogether,
<xsl:template match="product[category='Computers']" >
<!-- Do something with product nodes where their category is Computers. -->
</xsl:template>
<xsl:template match="product" >
<!-- Do nothing with product nodes of other categories. -->
</xsl:template>
<xsl:template match="/">
<products>
<xsl:apply-templates select="products/product" />
</products>
</xsl:template>
This uses a predicate, to make the one product-matching template more specific than the
others. For instance, the stylesheet may generate an HTML table, and style the rows
containing book records in the Computers category in cyan while others remain white.
(I've assumed in this last XSLT example snippet that you do have some containing document
element, like products, because of the requirement that there can be only one root element
and presumably there are multiple products so they must be children.)
Derek Harmon