I’m using xslt to create onscreen pdf’s from xml and I need to hide an xref but only when it appears within a title element.
For example:
<title><i>Naseem Akhtar v Birmingham City Council</i> [2011] EWCA Civ 383 <xref href="#Public_PUBLICLAW_PLLR_2011PLLR002">Click here for transcript</xref></title>
Here I would want to just display
Naseem Akhtar v Birmingham City Council</i> [2011] EWCA Civ 383
The value “Click here for transcript” remains contstant
I have tried the following wild stabs in the dark:
<xsl:template match="title">
<xsl:if test="xref=href">
<fo:block
font-weight="bold"
text-transform="uppercase">
<xsl:apply-templates />
</fo:block>
</xsl:if>
</xsl:template>
and also
<xsl:template match="title">
<xsl:if test="*[contains(@class,' topic/xref ')][not(@href='')]">
<fo:block
font-weight="bold"
text-transform="uppercase">
<xsl:apply-templates />
</fo:block>
</xsl:if>
</xsl:template>
but neither catch the xref.
Could someone please point me in the right direction please.
Thanks.
This short and simple transformation (no conditionals at al and only a single template):
when applied on the provided XML document:
produces the wanted, correct result:
Explanation:
If no templates are specified, an XSLT processor uses the built-in XSLT templates and the summary result of doing so is outputting all text nodes in document order.
We alter the effect of 1. above by overriding the built-in template that matches any element — for any
xrefelement that is a child oftitle. The overriding template has empty body, which in effect “deletes” the content of this element.