Project

Profile

Help

Newlines matching in analyze-string

Added by Anonymous almost 19 years ago

Legacy ID: #3468808 Legacy Poster: James Michael Wright (jimwrightbe)

The result of the test stylesheet below is: <?xml version="1.0" encoding="UTF-8"?> Product Name: SAXON Product Version: 8.4 Result: 2 but I would expect the last line to be Result: 1 because there is a newline within an XPath string in the analyze-string select expression. (Hope it is visible between single quotes.) To me, it is as if the newline is a space. Why? TIA Here is the stylesheet: <?xml version="1.0" encoding="utf-8"?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match="/"> Product Name: <xsl:value-of select="system-property('xsl:product-name')"/> Product Version: <xsl:value-of select="system-property('xsl:product-version')"/> Result: <xsl:analyze-string select="' '" regex="(\n)|( )"> <xsl:matching-substring> <xsl:choose> <xsl:when test="regex-group(1)">1</xsl:when> <xsl:when test="regex-group(2)">2</xsl:when> <xsl:otherwise> <xsl:message terminate="yes">Impossible condition</xsl:message> </xsl:otherwise> </xsl:choose> </xsl:matching-substring> <xsl:non-matching-substring> <xsl:value-of select="normalize-space(.)"/> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:template> </xsl:transform>


Replies (2)

RE: Newlines matching in analyze-string - Added by Anonymous almost 19 years ago

Legacy ID: #3469001 Legacy Poster: Michael Kay (mhkay)

XML parsers are required to normalize the whitespace appearing in attribute values: newlines are turned into spaces. This happens before the XSLT processor gets a look in. You can avoid this effect by writing the newline character as & # x a ; (spaces inserted to avoid reformatting). Michael Kay Saxonica

RE: Newlines matching in analyze-string - Added by Anonymous almost 19 years ago

Legacy ID: #3469696 Legacy Poster: James Michael Wright (jimwrightbe)

Thanks. That's more or less what I was thinking when I woke up 10 minutes ago ;-)

    (1-2/2)

    Please register to reply