Reputation: 163
I want to use processing-instruction in XSLT.
Logic: If there is <?Table Sideturn?>
it should add <context:sideturn>
Input:
<table-wrap id="tab_A.1" position="anchor">
<?Table Sideturn?>
<label>Table A.1</label>
<caption/>
<table>
<tbody/>
</table>
</table-wrap
Output should be:
<context:sideturn>
<table/>
</context:sideturn>
Tried code:
<xsl:template match="table">
<xsl:choose>
<xsl:when test="preceding-sibling::processing-instruction('Table Sideturn')">
<context:sideturn>
<table/>
</context:sideturn>
</xsl:when>
<xsl:otherwise>
<context:not-sideturn>
<table/>
</context:not-sideturn>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Above my xpath is not working well. How can I resolve this? I am using XSLT 2.0.
Thank you.
Upvotes: 0
Views: 58
Reputation: 101680
The processing instruction
<?Table Sideturn?>
Has a name of Table
and a value of Sideturn
. So you need to check for it based on its name and value:
<xsl:when
test="preceding-sibling::processing-instruction('Table')[normalize-space() = 'Sideturn']">
As noted in the comments, I'm using normalize-space()
here since some processors may treat the value as having a space at the beginning.
Upvotes: 1
Reputation: 841
You Can try this:
<xsl:when test="preceding-sibling::processing-instruction('Table Sideturn')">
Instead-of
<xsl:when test="preceding-sibling::processing-instruction('Table')">
Becouse Space is not allowed in element name.
Upvotes: 1