Re: [xsl] How does one go about extracting HTML anchors from an XML file?

Subject: Re: [xsl] How does one go about extracting HTML anchors from an XML file?
From: Jörg Heinicke <joerg.heinicke@xxxxxx>
Date: Mon, 17 Sep 2001 22:59:39 +0200

one big problem is your use of <xsl:call-template>. Avoiding those by using
<xsl:apply-templates> you can avoid such errors.

My XSL would be:

<xsl:template match="p">
        <xsl:apply-templates select="*|text()"/>

<xsl:template match="text()">
    <xsl:value-of select="."/>

<xsl:template match="href">
    <a href="http://{@link}";><xsl:value-of select="."/></a>

<xsl:template match="a">
    <a href="mailto:{@mailto}";><xsl:value-of select="."/></a>

This is shorter, not so prone to errors and much more readable.

Another point in my eyes would be the XML-code itself. A <href> and a <a> is
not so good, I think. Maybe better solution:
<link href="">...</link>
<mailto href="jacob_liat@xxxxxxxxxxx">...</mailto>



> Hello all,
> I'm trying to retrieve links and mailto anchors from an XML file and
> them in an HTML page ('a href' and 'a mailto' respectively). The problem
> running into is that I don't know how to extract these anchors properly
> while preserving the overall hierarchy of the nodes.
> Here's what my XML file looks like:
> <article>
>    <summary>
>       <p>blah blah blah blah blah blah
>          blah <href link=''> some link text here</href>
> blah blah <a mailto="jacob_liat@xxxxxxxxxxx>some text here</a>
> blah blah.</p>
>       <p>second paragraph with additional anchors embedded throughout
>          the paragraph text.</p>
>    </summary>
> </article>
> The corresponding XSL file is:
> <xsl:template match="p">
>    <P>
>       <xsl:choose>
>          <xsl:when test="href">
>             <xsl:for-each select="href">
>        <xsl:call-template name="href">
>           <xsl:with-param name="word">
>                      <xsl:value-of select="."/></xsl:with-param>
>        </xsl:call-template>
>     </xsl:for-each>
> </xsl:when>
> <xsl:when test="a">
>     <xsl:for-each select="a">
>        <xsl:call-template name="a">
>           <xsl:with-param name="addr">
>                      <xsl:value-of select="."/></xsl:with-param>
>        </xsl:call-template>
>     </xsl:for-each>
> </xsl:when>
>       </xsl:choose>
>    </P>
>    <xsl:value-of select="."/>
> </xsl:template>
> <xsl:template name="href">
>    <xsl:param name="word"/>
>       <A HREF="http://{@link}";><xsl:value-of select="$word"/></A>
> </xsl:template>
> <xsl:template name="a">
>    <xsl:param name="addr"/>
>       <A HREF="mailto:{@mailto}";><xsl:value-of select="$addr"/></A>
> </xsl:template>
> I'd greatly appreciate if anyone has any ideas and would kindly point me
> the right direction.
> Thanks in advance for any help,
> Liat

 XSL-List info and archive:

Current Thread