Note that there are some explanatory texts on larger screens.

plurals
  1. PONormalize whitespace in mixed-content elements, in XSLT 1.0
    primarykey
    data
    text
    <p>[EDIT: Changed title to better conceptualize the question.]</p> <p>The value of the attribute <code>@xml:space</code> can be either <code>"default"</code> or <code>"preserve"</code>. XML specifies what the second means but leaves the first up to the application. (I think I have that correct.) So what if the application wants <code>default</code> to implement XSchema's <code>collapse</code>? How could XSLT 1.0 actually do this?</p> <p>I think the built-in template for processing text, that is,</p> <pre><code>&lt;xsl:template match="text()"&gt; &lt;xsl:value-of select="."/&gt; &lt;/xsl:template&gt; </code></pre> <p>would need to be replaced with something like this pseudo-code:</p> <pre><code>&lt;xsl:choose&gt; &lt;xsl:when test="../@xml:space='preserve'" &lt;xsl:value-of select="."/&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; if position(.)=1 then output LTRIM(value-of(.)) if position(.)=last() then output RTRIM(value-of(.)) if position(.)= 1 and last()=1 then output normalize-space(.) &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; </code></pre> <p>This input then:</p> <pre><code>&lt;persName&gt; The man is &lt;forename&gt;Edward&lt;/forename&gt; &lt;forename&gt;George&lt;/forename&gt; &lt;surname type="linked"&gt;Bulwer-Lytton&lt;/surname&gt;, &lt;roleName&gt;Baron Lytton of &lt;placeName&gt;Knebworth&lt;/placeName&gt; &lt;/roleName&gt; &lt;/persName&gt; </code></pre> <p>would get rendered correctly as <code>The man is Edward George Bulwer-Lytton, Baron Lytton of Knebworth</code> with the space before <code>The man</code> and after <code>Knebworth</code> trimmed and the spaces between <code>Edward</code> and <code>George</code> collapsed. (The example is from TEI.)</p> <p>[EDIT: I removed an incorrect and misleading paragraph here.]</p> <p>The XSLT 1.0 to implement that pseudo-code would need to be executed for every text node. Wouldn't that be ugly and slow? [EDIT: Or maybe not. I simplified the pseudo code. Are there fast trim routines? Is the choose really that slow?]</p> <p>Bottom line: How does one implement XSchema's collapse in XSLT 1.0 (with only browser-embedded extensions)?</p> <p>I hope I'm saying all that correctly. And I hope the code is simple. I haven't yet seen how it can be. [EDIT: Changed xs:collapse to XSchema's collapse.]</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload