How to transfer XML-nodes unchanged to output with XSLT? -


i transforming xml document html document via xslt. xml document tolerates html-tags used within special tags:

<sequence>order pizza</sequence> 

or alternatively

<sequence>   <ol>     <li>order pizza</li>     <li>switch on television</li>   </ol> </sequence> 

how tell transformation transfer on tags <ol>, <li> etc. unchanged output - in case html follows:

<p>   <ol>     <li>order pizza</li>     <li>switch on television</li>   </ol> </p> 

in general, can choose 1 of 2 possible strategies.

either:

  • pass all nodes output unchanged default, , add templates matching nodes want modify exception;

or:

  • have template matches nodes want pass unchanged explicitly.

here's implementation of first strategy:

xslt 1.0

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/>  <!-- identity transform --> <xsl:template match="@*|node()">     <xsl:copy>         <xsl:apply-templates select="@*|node()"/>     </xsl:copy> </xsl:template>  <xsl:template match="sequence">     <p>         <xsl:apply-templates/>     </p> </xsl:template>  </xsl:stylesheet> 

in specific example, simply:

xslt 1.0

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/>  <xsl:template match="sequence">     <p>         <xsl:copy-of select="node()"/>     </p> </xsl:template>  </xsl:stylesheet> 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -