is it possible to convert the <p>
tags to <note>
tags using XSL?
Yes. You can use the following template:
<xsl:template match="p">
<xsl:element name="note">
<xsl:apply-templates select="node()|@*" />
</xsl:element>
</xsl:template>
If you want to transform only the <p>
elements whose text()
content starts with "!!!", use
<xsl:template match="p[starts-with(.,'!!!')]"> ...
and I want to use XSL to surround 'apiname' with tags
Also yes, use the following template:
Remark: you can't use a global variable in a template matching rule in XSLT-1.0
<xsl:variable name="api_replace" select="'apinamereplacement'" />
<xsl:variable name="api" select="'apiname'" />
<xsl:template match="p[contains(text(),'apiname')]">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:value-of select="substring-before(text(),$api)" />
<xsl:element name="{$api_replace}">
<xsl:value-of select="$api" />
</xsl:element>
<xsl:value-of select="substring-after(text(),$api)" />
</xsl:copy>
</xsl:template>
A complete template could look like this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="api_replace" select="'apinamereplacement'" />
<xsl:variable name="api" select="'apiname'" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="p">
<xsl:element name="note">
<xsl:apply-templates select="node()|@*" />
</xsl:element>
</xsl:template>
<xsl:template match="p[contains(text(),'apiname')]">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:value-of select="substring-before(text(),$api)" />
<xsl:element name="{$api_replace}">
<xsl:value-of select="$api" />
</xsl:element>
<xsl:value-of select="substring-after(text(),$api)" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>