Subject: [xsl] browser status on id/xml:id (idxml) From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx> Date: Wed, 25 Aug 2010 21:58:30 +0200 |
Hello, after being directed to use xml:id with the id() function in another thread I got another pointer from David Carlisle to using "id" in browsers. Adding xhtml namespace to an element allows to use its id attribute as id (browsers "know" that's an id). Now I did some experiments which browsers support what. First result is that the table [1] is wrong for xml:id support of Webkit. Safari as well as Chrome browser support xml:id. I created small samples for use of xml:id (xmlid.xml [2]) and "id with xhtml namespace" (id.xml [3]). Support is geven if you will see 4 lines of output generated. These are the results found: supports xml:id Chrome 5.0.375.126 Opera 10.01 Safari 4.0.4 supports "id with xhtml namespace" Firefox 3.6.8 Opera 10.01 supports neither IE6 IE8 I even installed the 4th preview of IE9 today on my childrens computer (they use Firefox) because of the xml:id support entry for Trident 5.0 (which is IE9) in [1]. But that preview does not even support the xml-stylesheet PI, so no such tests were possible. Because xml:id is mostly supported right now (and seems to be supported by IE9) that is definitely the way to go for browser based stylesheets making use of the id() function. So the question right now is how to enable Firefox for xml:id? I found a simple workaround for that in case you have control over the XML file or even generate it: - just add the xhtml namespace to eg. the top level element - add an id attribute to each and every element having an xml:id attribute with the same value. This enables the id() function to work for Firefox. And since the xml:id entries are the same just accessing xml:id in the stylesheet provides a "portable" stylesheet! See idxml.xml [4] as an example for this: <?xml-stylesheet href="xmlid.xsl" type="text/xsl"?> <a xml:id="a" id="a" xmlns="http://www.w3.org/1999/xhtml"> <b xml:id="b1" id="b1"> <c>1</c> <c>2</c> </b> <b xml:id="b2" id="b2"> <c>3</c> <c>4</c> </b> </a> This can be executed by xmlid.xsl [5] (written for xml:id only): <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output method="html"/> <xsl:template match="/"> <xsl:variable name="ids"> <xsl:for-each select="//*[local-name()='b']"> <xsl:value-of select="concat(@xml:id,' ')"/> </xsl:for-each> </xsl:variable> xmlid.xsl<br/> ids: <xsl:value-of select="$ids"/> (two lines of output to follow)<br/> <xsl:for-each select="id($ids)"> <xsl:value-of select="concat(name(),' ',@xml:id)"/> <br/> </xsl:for-each> </xsl:template> </xsl:stylesheet> [1] http://en.wikipedia.org/wiki/Comparison_of_layout_engines_(XML)#Core_technologies [2] http://stamm-wilbrandt.de/en/xsl-list/idxml/id.xml [3] http://stamm-wilbrandt.de/en/xsl-list/idxml/xmlid.xml [4] http://stamm-wilbrandt.de/en/xsl-list/idxml/idxml.xml [5] http://stamm-wilbrandt.de/en/xsl-list/idxml/xmlid.xsl Mit besten Gruessen / Best wishes, Hermann Stamm-Wilbrandt Developer, XML Compiler, L3 WebSphere DataPower SOA Appliances ---------------------------------------------------------------------- IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martin Jetter Geschaeftsfuehrung: Dirk Wittkopp Sitz der Gesellschaft: Boeblingen Registergericht: Amtsgericht Stuttgart, HRB 243294
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Good quality XSLT course , W. Hugh Chatfield I | Thread | Re: [xsl] browser status on id/xml:, David Carlisle |
Re: [xsl] Cannot include namespaces, pankaj . c | Date | Re: [xsl] browser status on id/xml:, David Carlisle |
Month |