xsl-list
[Top] [All Lists]

RE: Returning HTML tags from a function not working

2006-01-27 11:14:30

I changed return type to "node()*" but in the output HTML I 
don't see any <br /> tags.

Perhaps you used xsl:value-of to copy the data returned by the function to
the HTML result tree. This would extract the string value of the returned
nodes. You need to use xsl:copy-of or xsl:sequence.

Michael Kay
http://www.saxonica.com/



So my function looks like this:
<xsl:function name="xrsl:printdoc" as="node()*>
   <xsl:param name="docnode" as="element()*"/>
   <xsl:if test="$docnode[1]">
     <xsl:analyze-string  select="$docnode[1]" regex="\n">
       <xsl:matching-substring><br /></xsl:matching-substring>
       <xsl:non-matching-substring>
         <xsl:value-of select="normalize-space(.)"/>
       </xsl:non-matching-substring>
     </xsl:analyze-string>             
   </xsl:if>
</xsl:function>

In addition I noticed that if the input has HTML tags, they 
are being stripped out.

What I want is to copy the "doc" node verbatim but replace 
new lines with <br /> and normalise
spaces. So if the doc node has <b> </b> then they should be 
copied to the output as it is. 

Thanks,
Anupam.



--- Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:

You've specified the result of the function as xs:string. 
This means that
any elements in the result get atomized, and when you 
atomize an empty <br/>
element you get nothing (well, you get an empty string, 
which amounts to the
same thing...). Declare the result as node()* and all 
should be well.

My own style would be to use a template for this rather 
than a function.
It's not mandatory, but I think people expect when they see 
a call-template
that nodes will be constructed, and they don't expect that 
when the see a
function call.

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: Agnisys [mailto:agnisys(_at_)yahoo(_dot_)com] 
Sent: 26 January 2006 22:01
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Returning HTML tags from a function not working

Hi,
  I'm using Saxson XSLT 2.0 on a Linux system. 

Input looks like this:

<doc>
 Some text that can be 
 Multiline. It can also have lots of     spaces.
</doc>

The Output of XSL is set to HTML.

I need the output to retain the newlines but retain the spaces.

So I want the HTML to look like:
-----------------------------------------------
Some text that can be 
Multiline. It can also have lots of spaces.
-----------------------------------------------

Here is my function, but somehow the <br /> vanishes from the 
HTML and so I get one line only.
<xsl:function name="xrsl:printdoc" as="xs:string*">
  <xsl:param name="docnode" as="element()?"/>
  <xsl:if test="$docnode[1]">
    <xsl:analyze-string  select="$docnode[1]" regex="\n">
      <xsl:matching-substring><br /></xsl:matching-substring>
      <xsl:non-matching-substring>
        <xsl:value-of select="normalize-space(.)"/>
      </xsl:non-matching-substring>
    </xsl:analyze-string>             
  </xsl:if>
</xsl:function>

Please help!
Thanks,
Anupam.

 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


--~------------------------------------------------------------------
XSL-List info and archive:  
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--






--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--