|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Resolving ENTITY attributes
Re:
> >> Reading the XSLT spec, I don't see a way of resolving ENTITY-type
> >> attribute values.
> >...
> >> Is there a way to do this?
> >
> <!DOCTYPE xmldoc ... [
> <!ENTITY img1 SYSTEM "image1.gif" NDATA gif>
> ...
> ]>
> <xmldoc>
> ...
> <xmlimg src="img1"/>
> ...
> </xmldoc>
If you're working with IE5, you can use something like below to save
system ids and match entities to them. The Microsoft site warns about
using globals in stylesheets,
http://msdn.microsoft.com/xml/xsl/tutorials/script-eval.asp
so it might not work in all situations. 1) Is there a way to test for
the type of a node in the new draft? 2) The test only works if the
template rule is first and doesn't have a match pattern.
<!-- ******** default element templates ************ -->
<xsl:template>
<xsl:if test=".[nodeType() = 6]">
<xsl:eval>saveSystemId(this);</xsl:eval>
</xsl:if>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="textnode()"><xsl:value-of/></xsl:template>
<!-- ******** example rule ********* -->
<xsl:template match="sgmlimg">
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:eval>lookupSystemId(this,
"src");</xsl:eval>
</xsl:attribute>
</xsl:element>
</xsl:template>
<xsl:script>
//<![CDATA[
var sEntities = new Array();
function saveSystemId(oNode)
{
var sName = oNode.nodeName;
if (sName.length == 0)
return;
sEntities[sName] = oNode.systemId;
}
function lookupSystemId(oNode, sAttr)
{
var oAttrMap = oNode.attributes;
if (oAttrMap == null)
return;
var oAttrNode = oAttrMap.getNamedItem(sAttr);
if (oAttrNode == null)
return;
var sName = oAttrNode.value;
// or, if you can assume the attribute will always exist
// var sName = oNode.attributes.getNamedItem(sAttr).value;
if (sName.length == 0)
return;
return(sEntities[sName]);
}
//]]>
</xsl:script>
__________________________________
Gabriel Paiz III
SPX - Valley Forge T.I.S.
25691 Atlantic Ocean Drive Suite B-7
Lake Forest, CA 92630
USA www.vftis.com
__________________________________
Tel: (949) 460 0094
Fax: (949) 460 0095
e-Mail: gpaiz@xxxxxxxxx
__________________________________
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








