AnirD
AnirD

Reputation: 49

Adding Prefix in XSLT 3

How to add a prefix (7HH) if the value doesn't start with '7HH'?

Source XML

<DATA>
   <Name>90078</Name>
</DATA>

Expected output

<DATA>
   <Name>7HH90078</Name>
</DATA>

Upvotes: 1

Views: 34

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167716

Well

<xsl:template match="DATA/Name[not(starts-with(., '7HH'))]">
  <xsl:copy expand-text="yes">7HH{.}</xsl:copy>
</xsl:template>

plus <xsl:mode on-no-match="shallow-copy"/> to handle the rest should suffice if you really use an XSLT 3 processor.

Upvotes: 1

Related Questions