指定された入力パラメーターに従ってテンプレートを適用する必要があります。
入力 XML:
<?xml version="1.0"?>
<chapter xmlns="http://www.w3.org/1998/Math/MathML">
<section1>
<math><mtext>This is section1 mtext</mtext></math>
</section1>
<section2>
<math><mtext>This is section2 mtext</mtext></math>
</section2>
</chapter>
ユーザーが Xpath 式を入力パラメーターとして指定した場合、その特定の Xpath を選択し、テンプレートを適用する必要があります。
たとえば、ユーザーが入力パラメーターとして「/chapter/section1/」を指定した場合、必要な出力は次のとおりです。
<?xml version="1.0" encoding="UTF-8"?><chapter>
<section1>
<math>~rom1~This is section1 mtext</math>
</section1>
<section2>
<math>~rom~this is section2 mtext</math>
</section2>
</chapter>
ユーザーが「/chapter/section1/」と「/chapter/section2」を 2 つの入力パラメーターとして指定した場合、出力は次のようになります。
<?xml version="1.0" encoding="UTF-8"?><chapter>
<section1>
<math>~rom1~This is section1 mtext</math>
</section1>
<section2>
<math>~rom2~this is section2 mtext</math>
</section2>
</chapter>
ユーザーがパラメーターを指定しない場合、出力は次のようになります。
<?xml version="1.0" encoding="UTF-8"?><chapter>
<section1>
<math>~rom~This is section1 mtext</math>
</section1>
<section2>
<math>~rom~this is section2 mtext</math>
</section2>
</chapter>
以下のXSLTを試しました
<?xml version='1.0'?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://www.w3.org/1998/Math/MathML">
<xsl:param name="Xpath1"/>
<xsl:param name="Xpath2"/>
<xsl:template match="@*|node()"><xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy></xsl:template>
<xsl:template match="Xpath1//mtext"><xsl:text>~rom1~</xsl:text><xsl:apply-templates/></xsl:template>
<xsl:template match="Xpath2//mtext"><xsl:text>~rom2~</xsl:text><xsl:apply-templates/></xsl:template>
<xsl:template match="m:mtext"><xsl:text>~rom~</xsl:text><xsl:apply-templates/></xsl:template>
</xsl:stylesheet>
これが不可能な場合は、これを達成するための代替案を親切に提案してください