[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: usage of entities (for dummies)

Subject: RE: usage of entities (for dummies)
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 3 Aug 2006 11:26:32 +0100
usage of amp in xml
Adding to DC's response: 

> 2.) What is the difference of the usage of - for example - 
> "&amp;" and "&#38;"? 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/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.