[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Rethinking namespaces, attribute remapping(wasRe:
On Fri, 2002-09-27 at 19:26, Didier PH Martin wrote: > Didier replies: > If for each domain language I have to use a different stylesheet then I > do not re-enforce re-use of the existing stylesheets. It sounds like a > quick fix but not as a sound long term solution. OK, here is a generic stylesheet to tranform internal HLinks into XLinks (could easily be adapted for external ones too): Source: <html xmlns="http://www.w3.org/1999/xhtml" xmlns:hlink="http://www.w3.org/2002/06/hlink" xmlns:vdv="http://eric.van-der-vlist.com/whatever"> <head> <hlink:hlink namespace="http://www.w3.org/1999/xhtml" element="img" locator="@src" effect="embed" actuate="onLoad" onFailure="warn"/> </head> <body> <br vdv:foo="bar"/> <img src="whatever" vdv:foo="bar"/> </body> </html> XSLT (could easily be adapted to external HLinks): <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:hlink="http://www.w3.org/2002/06/hlink" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:template match="@*"> <xsl:param name="hlink"/> <xsl:if test="not(concat('@', name()) = $hlink/@locator)"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:if> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:variable name="hlink" select="/xhtml:html/xhtml:head/hlink:hlink[@element=local-name(current()) and @namespace=namespace-uri(current())]"/> <xsl:apply-templates select="$hlink/@*" mode="hlink"> <xsl:with-param name="node" select="."/> </xsl:apply-templates> <xsl:apply-templates select="@*"> <xsl:with-param name="hlink" select="$hlink"/> </xsl:apply-templates> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="@*" mode="hlink"/> <xsl:template match="@element" mode="hlink"> <xsl:attribute name="xlink:type" namespace="http://www.w3.org/1999/xlink"> <xsl:text>simple</xsl:text> </xsl:attribute> </xsl:template> <xsl:template match="@effect" mode="hlink"> <xsl:attribute name="xlink:show" namespace="http://www.w3.org/1999/xlink"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template> <xsl:template match="@actuate" mode="hlink"> <xsl:attribute name="xlink:actuate" namespace="http://www.w3.org/1999/xlink"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template> <xsl:template match="@locator" mode="hlink"> <xsl:attribute name="xlink:href" namespace="http://www.w3.org/1999/xlink"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template> <xsl:template match="@locator[starts-with(., '@')]" mode="hlink"> <xsl:param name="node"/> <xsl:attribute name="xlink:href" namespace="http://www.w3.org/1999/xlink"> <xsl:value-of select="$node/@*[name() = substring-after(current(), '@')]"/> </xsl:attribute> </xsl:template> <!-- more attributes to be defined --> </xsl:stylesheet> Result: vdv@ibook:~/repros/libxslt$ xslt hlink.xml hlink.xsl using libxslt <?xml version="1.0"?> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:hlink="http://www.w3.org/2002/06/hlink" xmlns:vdv="http://eric.van-der-vlist.com/whatever"> <head> <hlink:hlink namespace="http://www.w3.org/1999/xhtml" element="img" locator="@src" effect="embed" actuate="onLoad" onFailure="warn"/> </head> <body> <br vdv:foo="bar"/> <img xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="whatever" xlink:show="embed" xlink:actuate="onLoad" vdv:foo="bar"/> </body> </html> Enjoy, Eric -- Rendez-vous à Paris. http://www.technoforum.fr/integ2002/index.html ------------------------------------------------------------------------ Eric van der Vlist http://xmlfr.org http://dyomedea.com (W3C) XML Schema ISBN:0-596-00252-1 http://oreilly.com/catalog/xmlschema ------------------------------------------------------------------------
|
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
|