XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 31st, 2004, 06:31 PM
BanksySan's Avatar
BanksySan BanksySan is offline
A mule with a spinning wheel.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Wales
Posts: 113 BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 48 m 39 sec
Reputation Power: 7
MySpace
Getting XSLT to print a '<' and a '"'

Hi all,

I have an XML doc with has a hyperlink element in it. I need to output a HTML tag like so:

Code:
<a href="hyperlinkWrittenInXMLDoc" id="idWrittenInXMLDoc>


The following code gives an invalid character error which I expected, but what should I be doing instead?

Code:
<a id="<xsl:value-of select="@id" />

Reply With Quote
  #2  
Old January 31st, 2004, 09:02 PM
BanksySan's Avatar
BanksySan BanksySan is offline
A mule with a spinning wheel.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Wales
Posts: 113 BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 48 m 39 sec
Reputation Power: 7
MySpace
Sorted!!

All sorted now. Solution below for anyone interested:

Code:
<xsl:text disable-output-escaping="yes">
    <a href="
</xsl:text>

<xsl:value-of select="@destination" />

<xsl:text disable-output-escaping="yes">
    ">
</xsl:text>

<xsl:value-of select="." />

<xsl:text disable-output-escaping="yes">
    </a>
</xsl:text>

Reply With Quote
  #3  
Old February 1st, 2004, 07:47 PM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 282 fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 2 h 30 m 42 sec
Reputation Power: 6
In general, using d-o-e is not regarded as good practice.

An alternative method is to use xsl:element and xsl:attribute constructs, i.e.

<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select= .... />
</xsl:attribute>
</xsl:element>


- F

Reply With Quote
  #4  
Old February 1st, 2004, 08:05 PM
BanksySan's Avatar
BanksySan BanksySan is offline
A mule with a spinning wheel.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Wales
Posts: 113 BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 48 m 39 sec
Reputation Power: 7
MySpace
Nice one... cheers!

Thanks

Using the d-o-e method was getting a tiring and was leaving some bloody ugly code.

Another question though, how do I use this for elements with no closing tag? I need to create <input> tags too.

Dave

Last edited by BanksySan : February 1st, 2004 at 08:10 PM.

Reply With Quote
  #5  
Old February 1st, 2004, 08:30 PM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 282 fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 2 h 30 m 42 sec
Reputation Power: 6
Re d-o-e, do a web search on this and read comments on
this issue from people like Michael Kay, Jeni Tennyson and Wendell Piez. This will give you an understanding of the
thinking behind not using this construct except for a very
limited set of cases (CDATA being one).

> how do I use this for elements with no closing tag? I need to
> create <input> tags too.

All the "HTML" code you are writing should be XHTML-compliant.
For example the <br> tag should written as <br /> and <input>
written as (for example)

<input type="hidden" name="xxx" value="yyy"></input>

Try it out. All modern browsers support this (correct) syntax.

Here is an example from a stylesheet I wrote some time
ago:

<xsl:template match="//subcomponent">
<td valign="middle">
<b>Subcomponent:</b>
<xsl:value-of select="." />
<input type="hidden" name="subcomponent">
<xsl:attribute name="value">
<xsl:value-of select="." />
</xsl:attribute>
</input>
</td>
</xsl:template>


Enjoy
- F

Reply With Quote
  #6  
Old February 1st, 2004, 08:36 PM
BanksySan's Avatar
BanksySan BanksySan is offline
A mule with a spinning wheel.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Wales
Posts: 113 BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 48 m 39 sec
Reputation Power: 7
MySpace
Here is an interesting point.

If the <xsl:element> pair has no printable elements then the closing tag isn't printed, but the '/' isn't printed at the end of the tag either.

Thanks for you help.

Dave

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Getting XSLT to print a '<' and a '"'


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT