<a href> and xsl

Discussion in 'XML' started by Larry, Feb 5, 2007.

  1. Larry

    Larry Guest

    Hi,

    I'm trying to get the following working but I'm at a loss and dont
    know what is wrong with it:

    <div class="name">
    <a href=" <xsl:apply-templates select="key[text()='Location']"
    mode="getValue" /> " target="_blank">
    <xsl:apply-templates select="key[text()='Name']" mode="getValue" />
    <xsl:text> </xsl:text>
    </a>
    </div>

    any help?

    thansks
     
    Larry, Feb 5, 2007
    #1
    1. Advertising

  2. * Larry wrote in comp.text.xml:
    >Hi,
    >
    > I'm trying to get the following working but I'm at a loss and dont
    >know what is wrong with it:
    >
    ><div class="name">
    > <a href=" <xsl:apply-templates select="key[text()='Location']"
    >mode="getValue" /> " target="_blank">
    > <xsl:apply-templates select="key[text()='Name']" mode="getValue" />
    > <xsl:text> </xsl:text>
    > </a>
    ></div>


    You cannot use elements in attribute values, you have to use the special
    xsl:attribute element or attribute value templates, refer to the XSLT
    1.0 specification for details:

    http://www.w3.org/TR/xslt#creating-attributes
    http://www.w3.org/TR/xslt#dt-attribute-value-template

    Only the former will allow you to use apply-templates.
    --
    Björn Höhrmann · mailto: · http://bjoern.hoehrmann.de
    Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
    68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
     
    Bjoern Hoehrmann, Feb 5, 2007
    #2
    1. Advertising

  3. > <a href=" <xsl:apply-templates select="key[text()='Location']"
    > mode="getValue" /> " target="_blank">


    You can't issue an apply-templates call from inside an attribute value. Try:

    <a target="_blank">
    <xsl:attribute name="href">
    <xsl:apply-templates select="key[text()='Location']"
    mode="getValue" /> "

    .... in other words, create the <a> element, then add an attribute that
    has a computed value.


    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Feb 5, 2007
    #3
  4. Larry

    Larry Guest

    In article <45c757a5$1@kcnews01>,
    Joseph Kesselman <> wrote:

    > <a target="_blank">
    > <xsl:attribute name="href">
    > <xsl:apply-templates select="key[text()='Location']"
    > mode="getValue" /> "
    >
    > ... in other words, create the <a> element, then add an attribute that
    > has a computed value.


    ok, I got it. But now I'm having some trouble making a substitution,
    here's some code:

    <xsl:template match="dict">
    <div>
    <div class="name">
    <a target="_blank">
    <xsl:attribute name="href">
    <xsl:apply-templates select="key[text()='Location']"
    mode="getAsUri"/>
    </xsl:attribute>
    <xsl:apply-templates select="key[text()='Name']" mode="getValue" />
    <xsl:text> </xsl:text>
    </a>
    </div>
    </div>
    </xsl:template>

    <xsl:template match="key" mode="getValue">
    <xsl:value-of select="following-sibling::*[1]" />
    </xsl:template>

    <xsl:template match="key" mode="getAsUri">
    <xsl:variable name="txt">
    <xsl:apply-templates select="." mode="getValue" />
    </xsl:variable>
    <xsl:text>http://127.0.0.1:8000/</xsl:text>
    <xsl:value-of select="substring-after($txt,'file:///')"
    disable-output-escaping="yes" />
    </xsl:template>

    It should turn:

    file:///Users/etc...

    to:

    http://127.0.0.1:8000/Users/etc...

    sadly, it doesn't work properly as I only get http://127.0.0.1:8000/
    without the /Users/etc... part

    I can't work out what is wrong with the code

    any help?

    thanks
     
    Larry, Feb 5, 2007
    #4
  5. Larry

    Peter Flynn Guest

    Larry wrote:
    > In article <45c757a5$1@kcnews01>,
    > Joseph Kesselman <> wrote:
    >
    >> <a target="_blank">
    >> <xsl:attribute name="href">
    >> <xsl:apply-templates select="key[text()='Location']"
    >> mode="getValue" /> "
    >>
    >> ... in other words, create the <a> element, then add an attribute that
    >> has a computed value.

    >
    > ok, I got it. But now I'm having some trouble making a substitution,
    > here's some code:
    >
    > <xsl:template match="dict">
    > <div>
    > <div class="name">
    > <a target="_blank">
    > <xsl:attribute name="href">
    > <xsl:apply-templates select="key[text()='Location']" mode="getAsUri"/>


    That will select all child elements of dict called key, whose (implicit)
    first stretch of unmarked character data content is equal to "Location".
    The template for key will then provide a value starting with the quoted
    http method, IP address and port, plus the delocalised value of the text
    content of the first element following the key, omitting to escape the
    ampersands. Is this what you meant? Presumably the element following
    such a key element does indeed contain a URI.

    > </xsl:attribute>
    > <xsl:apply-templates select="key[text()='Name']" mode="getValue" />
    > <xsl:text> </xsl:text>
    > </a>
    > </div>
    > </div>
    > </xsl:template>
    >
    > <xsl:template match="key" mode="getValue">
    > <xsl:value-of select="following-sibling::*[1]" />
    > </xsl:template>
    >
    > <xsl:template match="key" mode="getAsUri">
    > <xsl:variable name="txt">
    > <xsl:apply-templates select="." mode="getValue" />
    > </xsl:variable>
    > <xsl:text>http://127.0.0.1:8000/</xsl:text>
    > <xsl:value-of select="substring-after($txt,'file:///')"
    > disable-output-escaping="yes" />
    > </xsl:template>
    >
    > It should turn:
    >
    > file:///Users/etc...
    >
    > to:
    >
    > http://127.0.0.1:8000/Users/etc...
    >
    > sadly, it doesn't work properly as I only get http://127.0.0.1:8000/
    > without the /Users/etc... part
    >
    > I can't work out what is wrong with the code


    If you provided us with some sample data so that we didn't have to work
    blind it would help...

    ///Peter
     
    Peter Flynn, Feb 5, 2007
    #5
  6. Larry

    Larry Guest

    In article <>,
    Peter Flynn <> wrote:

    > If you provided us with some sample data so that we didn't have to work
    > blind it would help...


    http://www.theartofweb.net/xml/wow.xml

    now, try and move your mouse over several links, you get the same:
    http://127.0.0.1:8000/

    instead, I'd like it to be like:
    http://127.0.0.1:8000/value_of_'Location'_without_this_at_the_beginning_f
    ile:///

    take a look at the file, its standalone kind of

    thanks
     
    Larry, Feb 5, 2007
    #6
  7. Larry

    Larry Guest

    In article <>,
    Larry <> wrote:


    > take a look at the file, its standalone kind of


    help!! I just want to transform this:

    <tag>file:///Users/</tag>

    to this:

    <tag>http://127.0.0.1:8000/Users</tag>
     
    Larry, Feb 5, 2007
    #7
  8. > help!! I just want to transform this:
    > <tag>file:///Users/</tag>
    > to this:
    > <tag>http://127.0.0.1:8000/Users</tag>


    If you want the URI to be relative to where the document was loaded
    from, why not just use a relative URI in the first place:

    <tag>/Users</tag>

    That makes this the browser's problem... and any browser ought to handle
    it properly.



    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, Feb 6, 2007
    #8
  9. Larry

    Peter Flynn Guest

    Larry wrote:
    > In article <>,
    > Larry <> wrote
    >
    > http://www.theartofweb.net/xml/wow.xml


    Not Found
    The requested URL /xml/wow.xml was not found on this server.
    Additionally, a 404 Not Found error was encountered while trying to use
    an ErrorDocument to handle the request.

    >> take a look at the file, its standalone kind of

    >
    > help!! I just want to transform this:
    >
    > <tag>file:///Users/</tag>
    >
    > to this:
    >
    > <tag>http://127.0.0.1:8000/Users</tag>


    <xsl:value-of select="concat('http://127.0.0.1:8000/',
    substring-after(tag,'file:///'))"/>

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie
     
    Peter Flynn, Feb 6, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    3,613
    A. Bolmarcich
    May 27, 2005
  2. CRON
    Replies:
    24
    Views:
    200,847
    Adrienne Boswell
    Jun 20, 2006
  3. saiho.yuen
    Replies:
    3
    Views:
    437
    kaeli
    Sep 14, 2004
  4. Replies:
    2
    Views:
    482
  5. Vincent van Beveren

    BASE HREF and A HREF="#" onclick="..."

    Vincent van Beveren, Jul 6, 2006, in forum: Javascript
    Replies:
    2
    Views:
    331
    Vincent van Beveren
    Jul 6, 2006
Loading...

Share This Page