>XSL Refactoring: Entities to Variables

>I ran across an interesting piece of code in the DocBook XSL Style sheets. The XSL Tools validator will try and syntax check the XPath statements to make sure they are at least syntatically correct. However, the XPath language itself doesn’t necessarily understand entities beyond the ones defined as base XML entities. So the following XSL statement was giving a validation error on the XPath statement:

<xsl:value-of select=”concat(‘image/’,
translate($format, &uppercase;, &lowercase;))”/>

The DTD entry that defines these entities looks like:

<!DOCTYPE xsl:stylesheet [
<!ENTITY lowercase “‘abcdefghijklmnopqrstuvwxyz'”>
<!ENTITY uppercase “‘ABCDEFGHIJKLMNOPQRSTUVWXYZ'”>
]>

The thing is that this can easily be refactored to use a global variable that is available to all the templates in the style sheet. The entities above can be represented as variables in the following manner:

<xsl:variable name=”lowercase”>abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name=”uppercase”>ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>

And now the xsl:value of can reference the variables:

<xsl:value-of select=”concat(‘image/’,
translate($format, $uppercase, $lowercase))”/>

The only question I have, is should the XPath validator in XSL Tools be expanding these entities before doing the validation? Technically with out expansion, the XSL Tools is correct that it isn’t a valid XPath statement.

Advertisements
This entry was posted in docbook, eclipse, xsl. Bookmark the permalink.

2 Responses to >XSL Refactoring: Entities to Variables

  1. Peter says:

    >I believe that these entities should be expanded during XML processing. Client which is reading XML should get expanded text.So when such text goes into XPath engine, it should only see expanded versions and not entity references.

  2. David Carver says:

    >There are some cases were the entity expansion is useful as a short cut for some complicated match statements.I guess XSL Tools is going to need an enhancement to our XPath validation to make sure we expand any entities before passing them into the parser.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s