- From: Tim Bray <tbray@textuality.com>
- Date: Fri, 27 Sep 2002 12:05:39 -0700
- To: Eric van der Vlist <vdv@dyomedea.com>
- Cc: www-tag@w3.org
On Friday, September 27, 2002, at 11:38 AM, Eric van der Vlist wrote:
> Since you seem to feel that it's an important issue, I have done the
> exercise and that's not *that* complex!
Thanks Eric. So if I wanted to write some XSLT to extract & process
all the XLinks and some other stuff in the XHTML, I'd use a two-step
process? Step one like this to generate XLinks in an easily-accessible
names, then step 2 is straightforward generic XSLT to reorganize the
XHTML and XLink and whatever else it contained?
For example... suppose we had some nice modern XHTML2 with
properly-nested DIVs and so on, and hyperlinks scattered around.
Suppose I wanted to produce a nested table of contents with just
hyperlinks, losing all the other text; basically lose anything that's
not a <div>, <h[0-8]>, or hyperlink.
How would the approaches compare if the source were XLink vs HLink?
-Tim
>
> 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
> -----------------------------------------------------------------------
> -
>
>
>
Received on Friday, 27 September 2002 15:05:41 UTC