XSLT & HTML

Discussion in 'XML' started by JustinCarmony, Jan 22, 2007.

  1. My employer wants me to explore the possibilities of XSLT for a new
    project I am working on. It seems to work great for some things, but
    here is an issue:

    My boss wants to make a XML based web service, and a XSLT template to
    parse that XML into a fully functioning webpage. There is the issue, I
    can modify content between HTML tags and such, but lets say the
    following example:

    -----------------------------------------------------------------------------------------------------------------------
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <div id="mainNav">
    <ul>
    <xsl:for-each select="/linkLists/linkList/link">
    <li class="home"><a href="#"><span></span><xsl:value-of
    select="defaultText" /></a></li>
    </xsl:for-each>
    </ul>
    </div>
    </xsl:template>
    </xsl:stylesheet>
    -----------------------------------------------------------------------------------------------------------------------

    I can change the default Text. However, I cannot change values within
    the <li> and <a> tags without getting an error. The following does not
    work:

    <li class="<xsl:value-of select="className" />"><a href="<xsl:value-of
    select="linkURL />"><span></span><xsl:value-of select="defaultText"
    /></a></li>

    Is there a way to accomplish this and parse correctly? Thank you.
     
    JustinCarmony, Jan 22, 2007
    #1
    1. Advertising

  2. JustinCarmony wrote:

    > <li class="<xsl:value-of select="className" />"><a href="<xsl:value-of
    > select="linkURL />"><span></span><xsl:value-of select="defaultText"
    > /></a></li>


    Use attribute value templates e.g.
    <li class="{className}"><a href="{linkURL}">
    see
    <http://www.w3.org/TR/xslt#attribute-value-templates>


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 22, 2007
    #2
    1. Advertising

  3. Thanks!

    Martin Honnen wrote:
    > JustinCarmony wrote:
    >
    > > <li class="<xsl:value-of select="className" />"><a href="<xsl:value-of
    > > select="linkURL />"><span></span><xsl:value-of select="defaultText"
    > > /></a></li>

    >
    > Use attribute value templates e.g.
    > <li class="{className}"><a href="{linkURL}">
    > see
    > <http://www.w3.org/TR/xslt#attribute-value-templates>
    >
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
     
    JustinCarmony, Jan 22, 2007
    #3
  4. JustinCarmony <> wrote:

    > <li class="<xsl:value-of select="className" />">


    <li>
    <xsl:attribute name"class">
    <xsl:value-of select="defaulText"/>
    <xsl:attribute>
    [...]
    </li>


    or a shorter version :
    <xsl:variable name="trick" select="defaultText"/>
    <li class="{$trick}">
    [...]
    </li>

    --
    Artaban de Médée
     
    =?ISO-8859-1?Q?Une_B=E9vue?=, Jan 22, 2007
    #4
  5. JustinCarmony

    Peter Flynn Guest

    JustinCarmony wrote:
    > <li class="<xsl:value-of select="className" />"><a href="<xsl:value-of
    > select="linkURL />"><span></span><xsl:value-of select="defaultText"
    > /></a></li>


    Others have posted suggested solutions; here's the explanation:
    XSLT is XML, so it has to follow the rules and be well-formed. You can't
    put element markup in an attribute value, and you can't nest quotes, so
    <li class="<xsl:value-of select="className" />">
    is a non-concept.

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/
     
    Peter Flynn, Jan 22, 2007
    #5
    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. Stylus Studio
    Replies:
    0
    Views:
    690
    Stylus Studio
    Aug 3, 2004
  2. Benjamin Hillsley
    Replies:
    3
    Views:
    1,692
    Dimitre Novatchev
    Sep 25, 2003
  3. ted
    Replies:
    1
    Views:
    626
    Laurens
    Jan 26, 2004
  4. Replies:
    2
    Views:
    726
    Henry S. Thompson
    Oct 19, 2005
  5. Replies:
    4
    Views:
    684
Loading...

Share This Page