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

RE: Rethinking namespaces, attribute remapping(wasRe:


xsl attribute name xlink href
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!

Buy Stylus Studio Now

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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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-2013 All Rights Reserved.