XSLT Question about | (pipe) vs 'or'
This is an open discussion with 2 replies, filed under XSLT.
Search
I am not sure you can do it in one single Xpath expression but you can do the following:
<xsl:apply-templates select="node-set/entry | another-set/entry"/> <xsl:template match="entry" /> <!-- don't display anything --> <xsl:template match="entry[1]"> <!-- override only the first one with the actual display--> lovely content </xsl:template>
I've only used |
as separator in my template match
attribute. In that context it can be used to match multiple nodes:
<xsl:template match="articles/entry | blogposts/entry" />
This will apply the template to both select statements
<xsl:apply-templates select="/data/articles/entry" /> <xsl:apply-templates select="/data/blogposts/entry" />
In your case, I would add logic in the form of <xsl:if />
or <xsl:choose>
to determine if the first nodes-set has any entries and execute the correct apply-templates selection based on that
Create an account or sign in to comment.
So, the pipe operator
|
doesn't actually do what I thought it did, I thought it was 'or' (that's because of PHP). It turns out it's a union operator to join node sets.The question I have is, can I use the
or
operator in it's place in a template match?I'm wanting to match the first node-set I specify
or
the next one if the first doesn't match anything, and only if it doesn't match anything...If both are present, I want to only match the first one. Is that possible?
Luckily so far I havent run into any issues using
|
in place ofor
because I haven't had both nodes present, but it will happen soon....