xsl-list
[Top] [All Lists]

RE: [xsl] usage of entities (for dummies)

2006-08-03 03:26:52
Adding to DC's response: 

2.) What is the difference of the usage of - for example - 
"&" and "&"? When do i have to use the one and not the other?

The first is technically an "entity reference", the second is a "character
reference". The only difference is that entities have to be declared in the
DTD, except for the five built-in ones. Numeric character references can be
used without needing a declaration.

3.) And where can i find a good overview of enitites?

I use Bob duCharme's "Annotated XML Specification" - very useful because it
gives the actual text of the specification, then Bob's explanation of what
it really means.

Finally i have also a non-entity question:
I have to replace many of equivalent placeholders in the same 
text too. Do i have to nest replace-functions for each of 
them in one another like ...
<xsl:value-of select="replace(replace(., '\^12', '&ccedil;'), 
'\^13', '&amp;')"/> ... or is there a more elegant solution for this?


As well as DC's solution, another approach is to have a table of
replacements:

<xsl:variable name="mods" as="element(mod)*">
  <mod from="\^12" to="&ccedil"/>
  <mod from="\^13" to="&amp;"/>
</xsl:variable>

and run through them with a recursive function:

<xsl:function name="f:multi-replace" as="xs:string">
  <xsl:param name="in" as="xs:string"/>
  <xsl:param name="mods" as="element(mod)*"/>
  <xsl:choose>
    <xsl:when test="$mods">
      <xsl:sequence select="f:multi-replace(
                              replace($in, $mods[1]/@from, $mods[1]/@to),
                              subsequence($mods, 2))"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:sequence select="$in"/>
    </xsl:otherwise>
  </
</

Michael Kay
http://www.saxonica.com/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--