|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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" /> |
|
#2
|
||||
|
||||
|
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>
|
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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. |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
||||
|
||||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Getting XSLT to print a '<' and a '"' |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|