|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Node renaming problem
Hello,
It's been over a year since I last worked with XSL and am having a difficult time remembering the simplest of things. In a current project, I want to add a prefix to a particular node tree such that <math> <apply> <power/> <ci>x</ci> <cn>2</cn> </apply> </math> becomes <m:math>
<m:apply>
<m:power/>
<m:ci>x</m:ci>
<m:cn>2</m:cn>
</m:apply>
</m:math>(The subnodes must carry the prefix because that is how the third-party browser plugin is configured to parse them.) I wrote the following named template, but I think I did it the hard way. Plus my test for text-only nodes is incorrect. <xsl:template name="str:prepend-ns"> <xsl:param name="tags" select="."/> <xsl:param name="ns" select="'alt'"/> <xsl:for-each select="$tags"> <xsl:choose> <!-- WRONG --> <xsl:when test=".=text()"> <xsl:copy-of select=."/> </xsl:when> <xsl:otherwise> <xsl:variable name="tagName" select="concat($ns, ':', local-name(.))"/> <xsl:element name="{$tagName}"> <xsl:call-template name="str:prepend-ns"> <xsl:with-param name="tags" select="child::node()"/> <xsl:with-param name="ns" select="$ns"/> </xsl:call-template> </xsl:element> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:template> This is the result using MSXSL4.0:
<m:math xmlns="">
<m:apply xmlns="">
<m:power xmlns="" />
<ci>x</ci>
<cn>2</cn>
</m:apply>
</m:math>1) How should I properly check to see if the current node is a text()? 2) How do I avoid the unnecessary xmlns="" attributes? 3) Am I overcomplicating everything?
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








