xml - Normalize whitespace in mixed-content elements, in XSLT 1.0 -
[edit: changed title better conceptualize question.]
the value of attribute @xml:space
can either "default"
or "preserve"
. xml specifies second means leaves first application. (i think have correct.) if application wants default
implement xschema's collapse
? how xslt 1.0 this?
i think built-in template processing text, is,
<xsl:template match="text()"> <xsl:value-of select="."/> </xsl:template>
would need replaced pseudo-code:
<xsl:choose> <xsl:when test="../@xml:space='preserve'" <xsl:value-of select="."/> </xsl:when> <xsl:otherwise> if position(.)=1 output ltrim(value-of(.)) if position(.)=last() output rtrim(value-of(.)) if position(.)= 1 , last()=1 output normalize-space(.) </xsl:otherwise> </xsl:choose>
this input then:
<persname> man <forename>edward</forename> <forename>george</forename> <surname type="linked">bulwer-lytton</surname>, <rolename>baron lytton of <placename>knebworth</placename> </rolename> </persname>
would rendered correctly the man edward george bulwer-lytton, baron lytton of knebworth
space before the man
, after knebworth
trimmed , spaces between edward
, george
collapsed. (the example tei.)
[edit: removed incorrect , misleading paragraph here.]
the xslt 1.0 implement pseudo-code need executed every text node. wouldn't ugly , slow? [edit: or maybe not. simplified pseudo code. there fast trim routines? choose slow?]
bottom line: how 1 implement xschema's collapse in xslt 1.0 (with browser-embedded extensions)?
i hope i'm saying correctly. , hope code simple. haven't yet seen how can be. [edit: changed xs:collapse xschema's collapse.]
here close want ...
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="/"> demonstration of collapsed white space. ======================================= <xsl:apply-templates select="*"/> </xsl:template> <xsl:template match="text()"> <xsl:value-of select="concat(normalize-space(.),' ')" /> </xsl:template> </xsl:stylesheet>
this produces output ...
demonstration of collapsed white space. ======================================= man edward george bulwer-lytton , baron lytton of knebworth
Comments
Post a Comment