开发者

XSL rendering a value INSIDE a form

THE SHORT VERSION: (hopefully you can 'see' what I'm trying to do here).... I want to 'output' a value from the XML into my form field in the XSL...

<input type="text" value='<xsl:value-of select="//return/ControlNo"/>' />  

this throws an error...(see below)


THE LONG VERSION: I have an XSL page rendering a page from XML... I need to 'log' when they 'close' that page - I thought calling a separate page onUnload would be the easiest way... HOWEVER - I need to pass an 'ID' to the logging page, so the XSL needs to EITHER pass the value in the onUload page call:

<BODY onUnload('logit.htm?ID= ...xsl:value-of...','logitwindow'); &gt;

OR - I submit a form with the value needed

<BODY onUnload(document.form.submit); >
<form><input type="hidden" name="id" value=" ...xsl:value-of... "></form>

I hope this makes sense.. thanks

the error... javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: org.xml.sax.SAXParseException: The value of attribute "value" associated with an element type "input" must not contain the '<' character. A Transformer object cannot be created that satisfies the configuration requested. This could be due to a failure in compiling the XSL text. javax.xml.transform.TransformerConfigurationException: javax.xml.transform.Trans开发者_开发问答formerException: org.xml.sax.SAXParseException: The value of attribute "value" associated with an element type "input" must not contain the '<' character.


<input type="text" value="{//return/ControlNo}" /> 

The {} is a xslt shortcut for "value-of" and is the equivalent of

<input type="text">
   <xsl:attribute name="value">
      <xsl:value-of select="//return/ControlNo" />
   </xsl:attribute>
</input>

If you use the long form you'll probibly have to set the output to HTML so that the INPUT is closed correctly


<input type="text" value='<xsl:value-of

select="//return/ControlNo"/>' />

this throws an error...

The problem with this is that in XML an attribute value is not allowed to contain any markup (tags), and the error thrown is in response to this violation.

There are two ways to do this correctly: short and long:

.1. Short way. Use:

<input type="text" value="{//return/ControlNo}"/>

Using {someExpression} inside an attribute value is called AVT -- Attribute-Value-Template. It causes someExpression to be evaluated and the evaluation result to replace this AVT.

.2. Long way. Use:

<input type="text">
  <xsl:attribute name="value">
    <xsl:value-of select="//return/ControlNo"/>
  </xsl:attribute>
</input>

This is an example how to use the XSLT instruction <xsl:attribute> to create an attribute with a specific name and a specific value. The created attribute must immediately follow the creation of an element (otherwise an error will be thrown). This attribute will become an attribute of the element it follows immediately.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜