This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Output a link in a transformation to html


Luare wrote:
> I am doing a transformation from xml to html.
> This example is not well-formed, why?

Because XSL is XML.
XML has a concept of well-formedness.

>     <H3>Web: <A HREF= <xsl:value-of select="."/>> <xsl:value-of select="."/>
> </A></H3>
> 
> The expresion <xsl:value-of select="."/> return a string, doesn't it?

XSL is not a scripting language where the source code is interpreted as raw 
instructions, and xsl:value-of is not a macro or function that returns 
anything.

A stylesheet represents a tree of nodes that follow the XPath/XSLT data 
model. It is this tree (the stylesheet tree) that is interpreted by an XSL 
processor, along with another tree derived from an XML document (the source 
tree). Elements in the stylesheet tree that are in the recognized XSLT 
namespace are interpreted as instructions to the processor that tell it how 
to go about constructing a third tree, the result tree. After this tree is 
constructed, a linear representation of that tree may (and usually is) 
output, following the syntax rules of XML or HTML or whatever was requested 
and supported.

xsl:value-of is an instruction that tells that XSL processor to put a text 
node in the result tree.

<H3>...</H3> and <A>...</A> are literal result elements that are treated as 
shorthand for these instructions to add elements to the result tree:

<xsl:element name="H3">...</xsl:element>
<xsl:element name="A">...</xsl:element>

This is what you want:

  <H3>Web: <A HREF="{.}"><xsl:value-of select="."/></A></H3>

You can also do something like this, which is useful if you need to do
something more complex than a single value-of in order to calculate the
attribute values:

<H3>
  <xsl:text>Web: </xsl:text>
  <A>
    <xsl:attribute name="HREF">
      <xsl:value-of select="."/>
    </xsl:attribute>
    <xsl:value-of select="."/>
  </A>
</H3>

> It seem a tipical error, but I am a beginner.

It's a FAQ, yes. You just need to get a better sense of XSL's processing 
model. See the FAQ at http://www.dpawson.co.uk/ and also get Michael Kay's
XSLT book.

   - Mike
_____________________________________________________________________________
mike j. brown, software engineer at  |  xml/xslt: http://skew.org/xml/
webb.net in denver, colorado, USA    |  personal: http://hyperreal.org/~mike/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]