Subject: [xsl] merging multiple xsl's - creates new node and ignores CDATA tags From: "Karlmarx Rajangam" <karlmarx.rajangam@xxxxxxxxxxxxxxxxxx> Date: Tue, 13 Nov 2007 05:51:17 -0500 |
The problem I have is in merging multiple xsl files into a single file, USING ANOTHER XSL file. Basically, we have dozens of xsl files with <xsl:include>, to include common things that are kept in files like header.xsl, footer.xsl etc. Example (trimmed minimal sample code) - Pls ignore any spell or upper/lower case typo errors. a) mainFile.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:include href="qmFooter.xsl"/> <xsl:template match="mResponse"> <xsl:if test="$doctype"><xsl:text disable-output-escaping="yes"><!DOCTYPE </xsl:text><xsl:value-of select="$doctype"/><xsl:text disable-output-escaping="yes"> ></xsl:text></xsl:if> <html> <head>..... </head> <body> <!-- so many blah blah statements --> <xsl:apply-templates/> <xsl:call-template name="qmFooter"/> </body> </html> </xsl:template> </xsl:stylesheet> b) qmFooter.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template name="qmFooter"> <div class="qm_FOOTNOTE"><xsl:value-of select="./header/licenseText"/></div> </xsl:template> </xsl:stylesheet> Due to a speacial need we have had to make another SINGLE file merging the <include>d files into main file. So, instead of merging physically, made another xslt to do this process, using XMLSPY -> xslTransformation c) Tranformation.xsl (actual code) <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:template match="/"> <xsl:apply-templates select="*"/> </xsl:template> <!-- the default copying process - match every node whether it is an element or an attribute --> <xsl:template match="node()|@*"> <xsl:choose> <xsl:when test="name() = 'xsl:include'"> <xsl:variable name="includeFile" select="@href"/> <xsl:comment> ********************************************************************** Content of file <xsl:value-of select="$includeFile"/> ********************************************************************** </xsl:comment> <xsl:variable name="includeContent" select="document($includeFile)"/> <xsl:copy> <xsl:apply-templates select="$includeContent/xsl:stylesheet/*"/> </xsl:copy> </xsl:when> <xsl:otherwise> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> This do the merging, but adds an <xsl:include> node on the output as shown below <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <!-- ********************************************************************** Content of file qmFooter.xsl ********************************************************************** --> <xsl:include> <!-- I NEED TO AVOID THIS xsl:include HERE. also, pls tell me: 1. WHY AND HOW THIS NODE GETS ADDED HERE 2. What change is required in Tranformation.xsl to eliminate this. --> <xsl:template name="qmFooter"> <div class="qm_FOOTNOTE"><xsl:value-of select="./header/licenseText"/></div> </xsl:template> </xsl:include> <xsl:template match="mResponse"> <xsl:if test="$doctype"> <xsl:text disable-output-escaping="yes"><!DOCTYPE </xsl:text> <xsl:value-of select="$doctype"/> <xsl:text disable-output-escaping="yes"> ></xsl:text> </xsl:if> <html> <head>..... </head> <body> <!-- so many blah blah statements --> <xsl:apply-templates/> <xsl:call-template name="qmFooter"/> </body> </html> </xsl:template> </xsl:stylesheet> 3) Also noticed, any opening and closing CDATA tag getting ignored <![CDATA[But, this text come ok]]>. Example <script type="text/javascript"><![CDATA[if ((document.forms[0] != null) && (document.forms[0].name == "END")) { SB_SetCanExit(true); }]]> </script> becomes <script type="text/javascript">if ((document.forms[0] != null) && (document.forms[0].name == "END")) { SB_SetCanExit(true); }</script> Is there a way to fix this? 4~) And let me know of any tother improvement or changes required in Tranformation.xsl Thanks in adv, karl
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] fo:inline within fo:basic, Khaled Aly | Thread | Re: [xsl] merging multiple xsl's - , David Carlisle |
Re: [xsl] fo:inline within fo:basic, David Carlisle | Date | Re: [xsl] merging multiple xsl's - , David Carlisle |
Month |