xsl-list
[Top] [All Lists]

[xsl] text() vs xs:string serialization (was: Re: [xsl] text extraction)

2006-10-12 07:10:25

This is awful form,  but I'm going to respond to my own answer
with a question.  One of the things I played around with when
writing the message below was how the serialization handled
separation of the output sequences.

Am I correct in my understanding that the reason the stylesheet
below works, separating each item from the <xsl:sequence/> with
a single whitespace character, is due to

 http://www.w3.org/TR/xslt-xquery-serialization/#serdm

where a sequence of strings will be padded, but a sequence of
text nodes will not be?  In other words, is that reference
above the reason that either

  <xsl:sequence select="string(.)"/>

or

  <xsl:sequence select="normalize-space(.)"/>

work, giving, 'text1 text2 text3', whereas

  <xsl:sequence select="."/> <!-- selecting text() node -->

would result in 'text1text2text3' ?
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">
  <xsl:output method="text"/>
  <xsl:template match="node()">
    <xsl:apply-templates select="node()"/>
  </xsl:template>
  <xsl:template match="text()[parent::*[self::E1|self::E2]]">
    <xsl:sequence select="normalize-space(.)"/>
  </xsl:template>
</xsl:stylesheet>

That would let you handle, for example, something like

<V><E1>text<E2>text2<baz>smorth</baz></E2>text3<flober>chum</flober></E1></V>

Jim

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
James A. Robinson                       
jim(_dot_)robinson(_at_)stanford(_dot_)edu
Stanford University HighWire Press      http://highwire.stanford.edu/
+1 650 7237294 (Work)                   +1 650 7259335 (Fax)

--~------------------------------------------------------------------
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>
--~--


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
James A. Robinson                       
jim(_dot_)robinson(_at_)stanford(_dot_)edu
Stanford University HighWire Press      http://highwire.stanford.edu/
+1 650 7237294 (Work)                   +1 650 7259335 (Fax)

--~------------------------------------------------------------------
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>
--~--