Sign In/My Account | View Cart  
advertisement

Article:
 Shortening XSLT Stylesheets
Subject: Another tip: Entity References
Date: 2003-06-11 17:43:13
From: Doug Ransom

I like to use entity references for repeated strings and reusable portions of xpaths, especially for concatenating xpath statements together to form a longer path.
For example


<!DOCTYPE xsl:stylesheet [
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
<!ENTITY rss "http://purl.org/rss/1.0/" >
<!ENTITY content "http://purl.org/rss/1.0/modules/content/">
<!ENTITY xsl "http://www.w3.org/1999/XSL/Transform" >
<!ENTITY html "http://www.w3.org/1999/xhtml">
<!ENTITY linkpredbase "html:link[@rel='alternate'][@type='application/rss+xml']">
<!ENTITY linkpred "&linkpredbase;[contains(@href,':')]" >
<!ENTITY rellinkpred "&linkpredbase;[@href][not(contains(@href,':'))]">
<!ENTITY relrsslink "html:head[&linkpredbase;]">
<!ENTITY rsslink "html:head[&linkpred;]">
<!ENTITY baseuri "html:base/@href">
<!ENTITY badChannelLocation "/html:html[descendant::rss:channel[preceding::rss:*]]">
<!ENTITY content-meta "/html:html/html:head/html:meta[@name='copy-descriptions-to-content']">
<!ENTITY linkWithAnchorStart "rss:link[descendant::html:a/@href" >
<!ENTITY linkWithAnchor "&linkWithAnchorStart;]">
<!ENTITY dc-meta "html:meta[starts-with(@name,'DC')]">
<!ENTITY dc "http://purl.org/dc/elements/1.1/">
]>
....
<xsl:when
test="&content-meta;">
<xsl:value-of select="&content-meta;/@content" />
</xsl:when>





No Previous Message Previous Message   Next Message Next Message


Titles Only Full Threads Newest First
  • Another tip: Entity References
    2003-06-15 06:15:25 manfred Knobloch [Reply]

    Good strategy if you can use DTDs. This restriction makes me use other ways. Sometimes i take the document() function to include larger parts. The advantage over Entities is that the values come in at stylesheet runtime. Expansion of entities is done at parsing time. So you have no conditional inclusion of values.
    But you are right: Entities are made for shortcutting.


Sponsored By: