Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 13th, 2007, 01:52 AM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please help me out with XML-HTML tranformation

Hi,
I'm trying some xml to html examples, and I'm kinda stuck. For example i have the following xml

Code:
 <para>
        Hi pls visit my website at <url>http://www.abc.com</url>.
 </para>
Could anyone help me form it into something that look like:

Quote:
quote:Hi pls visit my website at http://www.abc.com
using XSLT?

Sorry for my bad english.

Thank you Smile

 
Old May 13th, 2007, 02:40 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You say you're stuck but you don't say where. What XSLT do you have at the moment?

--

Joe (Microsoft MVP - XML)
 
Old May 13th, 2007, 03:19 AM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi, sorry here is what I have

<xsl:template match="para">
        <xsl:value-of select="."/>
        <p>
            <xsl:apply-templates select="url"/>
        </p>
</xsl:template>

<xsl:template match="url">
      <a>
        <xsl:attribute name="href">
            <xsl:value-of select="//url">
        </xsl:attribute>
      </a>
</xsl:template>

But I keep getting output similiar to this:

Hi pls visit my website at http://www.abc.com http://www.abc.com


 
Old May 13th, 2007, 04:35 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Your main error is not employing the context correctly. For example when you are inside the url template the context node is url so you can access it via '.', you don't need to query the whole document using //url.
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
    <html>
      <body>
       <xsl:apply-templates select="para"/>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="para">
    <xsl:value-of select="text()[1]"/>
    <xsl:apply-templates select="url"/>
  </xsl:template>

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

</xsl:stylesheet>
--

Joe (Microsoft MVP - XML)
 
Old May 13th, 2007, 04:41 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<xsl:template match="url">
      <a>
        <xsl:attribute name="href">
            <xsl:value-of select="//url">


"//url" means "All the url elements in the document". So every time you match a URL, you output the values of all the URLs in the document. At least, that's what XSLT 2.0 does. In XSLT 1.0, when xsl:value-of is given a node-set then it outputs the value of the first node in the set.

You want "." here, to mean "the current url element".

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
xml-xslt tranformation rajesh_css XSLT 2 September 17th, 2008 08:25 PM
Is XML supports transformation of HTML to XML? zeeonline XSLT 1 July 28th, 2006 05:13 PM
About HTML and XML sachinkumar XML 1 June 28th, 2005 10:30 AM
XML to HTML shoei78 XSLT 2 June 24th, 2003 08:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.