0

I am coding xslt to find the max row value of an element 'item' as the example shown in here. And per suggestions received, I tried code from here. However the '<=' operator causes parse error:

./ui.xsl:16: parser error : Unescaped '<' not allowed in attributes values                           
                                              not(@column < preceding-sibling::i

When I wrote code as:

  <xsl:variable name="maxRow" select="/ui/layout/item
                                            [
                                              not(@row <= preceding-sibling::item/@row) and
                                              not(@row <= following-sibling::item/@row)
                                            ]/@row" />

After I change the code to:

  <xsl:variable name="maxRow" select="/ui/layout/item
                                            [
                                              not(preceding-sibling::item/@row > @row) and
                                              not(following-sibling::item/@row > @row)
                                            ]/@row" />

The code starts to work just fine. I am using xsltproc as my processor. I believe '<=' is a standard XPATH 1.0 operator. How come it's not recognized by the processor?

Max Li
  • 551
  • 2
  • 14

2 Answers2

1

The problem is not with XPath, but rather with XML. The reason is described in the XML 1.0 specification, Section "Start-Tags". A Start-Tag is defined as follows:

STag       ::=      '<' Name (S Attribute)* S? '>'
Attribute  ::=      Name Eq AttValue 
... (following the link to 'AttValue')
AttValue   ::=      '"' ([^<&"] | Reference)* '"'
                 |  "'" ([^<&'] | Reference)* "'"

As you can see in the above rule, the AttValue definition excludes both chars, < and &. They cannot be part of the attribute value. The latter is only allowed as part of the Reference rule. Normally, both chars have to be escaped as Entity References according to these rules (WikiPedia).

Additional info:

Note:
Although the EntityValue production allows the definition of a general entity consisting of a single explicit < in the literal (e.g., <!ENTITY mylt "<">), it is strongly advised to avoid this practice since any reference to that entity will cause a well-formedness error.

Summary: You cannot use the char < in an attribute value in XML.
Affirmation: Your solution of inverting the comparison is the way to go in this case.

zx485
  • 28,498
  • 28
  • 50
  • 59
0

You can invert the logic and use > as suggested by @zx485, or you can just use &lt; or &lt;=.

kjhughes
  • 106,133
  • 27
  • 181
  • 240