xslt - Apply templates based on Input Parameter -
i in need apply templates according input parameter given.
input xml:
<?xml version="1.0"?> <chapter xmlns="http://www.w3.org/1998/math/mathml"> <section1> <math><mtext>this section1 mtext</mtext></math> </section1> <section2> <math><mtext>this section2 mtext</mtext></math> </section2> </chapter> if user gives xpath expression input parameter, particular xpath should selected , templates should applied.
for example, if user gives, "/chapter/section1/" input parameter required output is
<?xml version="1.0" encoding="utf-8"?><chapter> <section1> <math>~rom1~this section1 mtext</math> </section1> <section2> <math>~rom~this section2 mtext</math> </section2> </chapter> if user gives, "/chapter/section1/" , "/chapter/section2" 2 input parameters then, output should be
<?xml version="1.0" encoding="utf-8"?><chapter> <section1> <math>~rom1~this section1 mtext</math> </section1> <section2> <math>~rom2~this section2 mtext</math> </section2> </chapter> if user not give parameters, output should
<?xml version="1.0" encoding="utf-8"?><chapter> <section1> <math>~rom~this section1 mtext</math> </section1> <section2> <math>~rom~this section2 mtext</math> </section2> </chapter> i tried below 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> if way not possible kindly suggest alternative achieve this
Comments
Post a Comment