Subject: RE: [xsl] question about import/include From: "Craig Kattner" <CKattner@xxxxxxxxxxxxxx> Date: Fri, 4 Apr 2003 11:02:58 -0600 |
Just tried it in saxon 6.5.2 from the command line, and in both cases it results in (which is, again, not what I expected): <p class="categoryBody">This is a test. This is only a test.d</p> -----Original Message----- From: Craig Kattner Sent: Friday, April 04, 2003 10:51 AM To: XSL List (E-mail) Subject: [xsl] question about import/include I have the following stylesheet with a named template called "convert_linefeeds" which converts CRLF's to new paragraphs of html. It works fine when the named template is part of the stylesheet. However, I want to reuse it in other places but when using import/include the template doesn't work. <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="UTF-8" /> <xsl:template match="/"> <xsl:call-template name="convert_linefeeds"> <xsl:with-param name="input" select="//desc" /> </xsl:call-template> </xsl:template> <!-- Adapted from XSLT Cookbook, First Editiion by Sal Mangano page 13 --> <xsl:template name="convert_linefeeds"> <xsl:param name="input" /> <xsl:choose> <!-- see if the input contains the search string --> <xsl:when test="contains($input, ' ')"> <!-- if so, then contatenate the substring before the search string to the replacement string and to the result of recursively applying this template to the remaining substring --> <p class="categoryBody"> <xsl:value-of select="substring-before($input, ' ')" />a </p> <xsl:call-template name="convert_linefeeds"> <xsl:with-param name="input" select="substring-after($input, ' ')" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <!-- no more occurences of the search string so, just return the current input string --> <p class="categoryBody"> <xsl:value-of select="$input" />b </p> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> This is a sample document that it works with. <?xml version="1.0" encoding="UTF-8"?> <root> <desc>This is a test. This is only a test.</desc> </root> The result (which is what I expect): <p class="categoryBody">This is a test.a</p> <p class="categoryBody">This is only a test.b</p> That works fine. But, I want to use the convert_linefeeds template in several other templates, so I break it out into a separate file: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" encoding="UTF-8" /> <!-- Adapted from XSLT Cookbook, First Editiion by Sal Mangano page 13 --> <xsl:template name="convert_linefeeds"> <xsl:param name="input" /> <xsl:choose> <!-- see if the input contains the search string --> <xsl:when test="contains($input, ' ')"> <!-- if so, then contatenate the substring before the search string to the replacement string and to the result of recursively applying this template to the remaining substring --> <p class="categoryBody"> <xsl:value-of select="substring-before($input, ' ')" />c </p> <xsl:call-template name="convert_linefeeds"> <xsl:with-param name="input" select="substring-after($input, ' ')" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <!-- no more occurences of the search string so, just return the current input string --> <p class="categoryBody"> <xsl:value-of select="$input" />d </p> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> And include it in a new stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:include href="convert_linefeeds.xsl" /> <xsl:output method="html" encoding="UTF-8" /> <xsl:template match="/"> <xsl:call-template name="convert_linefeeds"> <xsl:with-param name="input" select="//desc" /> </xsl:call-template> </xsl:template> </xsl:stylesheet> Results in (missing </p><p> tags): <p class="categoryBody">This is a test. This is only a test.d</p> It doesn't error out, but the output isn't wrapped in <p></p> as I expect. Using MSXML 4.0 for this. (Incidentally, it does appear to work using a PI in the browser, but not from ASP or the msxsl command line. That would seem to indicate an MSXML problem I think.) Craig XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] question about import/inc, David Carlisle | Thread | [xsl] patterns, Terence |
RE: [xsl] Parsing XML tag attribute, Holbrook, R Cody (Co | Date | [xsl] patterns, Terence |
Month |