Reputation: 83
My Input XML is,
<link idref="r164">2004</link>
Output should be,
<link idref="r164" target="literature">2004</link>
The conditions are attribute "idref" value should be start with "r" and the link elements contain only 4 digit then we should add the attribute "target="literature"".
Could you please guide us to resolve this issue.
Upvotes: 0
Views: 176
Reputation: 3247
You can create a template as below.
<xsl:template match="link">
<xsl:copy>
<xsl:if test="starts-with(@idref, 'r') and string-length(.) = 4">
<xsl:copy-of select="@*" />
<xsl:attribute name="target">
<xsl:value-of select="'literature'" />
</xsl:attribute>
<xsl:value-of select="." />
</xsl:if>
</xsl:copy>
</xsl:template>
Upvotes: 1