Re: [xsl] Outputting XML to hidden HTML form fields

Subject: Re: [xsl] Outputting XML to hidden HTML form fields
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 15 Jan 2001 17:55:27 GMT
> I need to output a raw XML node to a hidden HTML form field.

There are two things to note here. Firstly in the XPath tree model
of an XML document (and most other models) Attributes
do not contain element nodes, only text.

Also in the linearisation of an XML file in XML syntax, an attribute
value may not contain an unescaped < you have to use &lt;.


<input type="hidden">
	<xsl:attribute name="name">
		_desc_<xsl:value-of select="id"/>
	</xsl:attribute>

	<!-- the above works fine. -->

The above is OK, but could more easily have been written
<input type="hidden" name="_desc_{id}">

(assuming you didn't really want the white space before _desc_)


	<xsl:attribute name="value">
		<xsl:copy>

You haven't shown your full template so I don't know for sure what is
the current node at this point, but probably it's the item node.
copying any element node into an attribute value is not going to work
for the reasons above.

What I think you want is
<xsl:attribute name="value">
  <xsl:text>&lt;item&gt;</xsl:text>
  <xsl:for-each select="*">
  <xsl:text>&lt;</xsl:text>
	<xsl:value-of select="name(.)"/>
  <xsl:text>&gt;</xsl:text>
	<xsl:value-of select="."/>
  <xsl:text>&lt;/</xsl:text>
	<xsl:value-of select="name(.)"/>
  <xsl:text>&gt;</xsl:text>
  </xsl:for-each>
  <xsl:text>&lt;/item&gt;</xsl:text>
</xsl:attribute>

David

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit
http://www.star.net.uk/stats.asp

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


Current Thread