views:

80

answers:

1

I am using an if statement that tests the amount of lines in a cell.

<xsl:if test="string-length(@Example) - string-length(translate(@Example, '&#xa;', '')) &lt; 10">

When I type in this code and hit save, that code turns into this:

<xsl:if test="string-length(@Example) - string-length(translate(@Example, '
', '')) &lt; 10">

Instead of &#xa;, I get a literal blank line.

I'm not using a <xsl: stylesheet> because I don't quite understand it and prefer not to use it. I'd be happy if someone could help me make it so that this doesn't happen (&#xa; turns into literal), or better yet, provide me another method for testing how many lines are in @Example. Thanks.

A: 

From http://www.w3.org/TR/REC-xml/#AVNormalize

  1. All line breaks MUST have been normalized on input to #xA as described in 2.11 End-of-Line Handling, so the rest of this algorithm operates on text normalized in this way.

  2. Begin with a normalized value consisting of the empty string.

  3. For each character, entity reference, or character reference in the unnormalized attribute value, beginning with the first and continuing to the last, do the following:

    • For a character reference, append the referenced character to the normalized value.
    • For an entity reference, recursively apply step 3 of this algorithm to the replacement text of the entity.
    • For a white space character (#x20, #xD, #xA, #x9), append a space character (#x20) to the normalized value.
    • For another character, append the character to the normalized value.

So, non new-line caracter (#xA) will be keep unless it's declare as a caracter reference in the source.

Alejandro
Sorry but this answer didn't help. I'm dealing with xsl, not xml, right now. Any other help out there?
ShareOnPoint
@ShareOnPoint: This answer explains why you can't do what you want to. XSLT input are XML trees (either parsed XML document or built by DOM, or else). So, attribute values get normalize as this spec describe.
Alejandro
OK, then. Thanks.
ShareOnPoint
@ShareOnPoint: No problem. You could do this but with XSLT 2.0 because it can use unparsed documents as input. Of course, you will loose XPath navegation but you could use some regexp matching.
Alejandro