XSLT single and double quotes in attribute of input form value?

Hopefully a quick question, how can I get this to be well formed and therefore work?

<input type="rad" name="RadGroup" value="<xsl:value-of select="productOptionInfo"/>" /> 

Basically I want to have a value placed inside an attribute value, but they need double quotes!!

Any ideas?

Many thanks

+6
xml xslt
source share
4 answers

XSLT has a shortcut for using values ​​inside attributes:

 <input type="rad" name="RadGroup" value="{productOptionInfo}" /> 

There is another option that it should use xsl:attribute :

 <input type="rad" name="RadGroup"> <xsl:attribute name="value"> <xsl:value-of select="productOptionInfo"/> </xsl:attribute> </input> 
+10
source share

This is not true :

 <input type="rad" name="RadGroup" value="<xsl:value-of select='productOptionInfo'/>" /> 

, and this is also wrong. :

 <input type="rad" name="RadGroup" value='<xsl:value-of select="productOptionInfo"/>' /> 

In XML, this is a syntax error for (unescaped) markup as attribute values . See W3 XML Spec - here and here .

Two correct ways to do this (called AVT attribute value templates or ):

 <input type="rad" name="RadGroup" value="{productOptionInfo}"/> 

and

 <xsl:attribute name="input"> <xsl:value-of select="productOptionInfo"/> </xsl:attribute> 

In XSLT 2.0 it is allowed to write :

 <xsl:attribute name="input" select="productOptionInfo"/> 

The first path above is the shortest and most readable when the element name is statically known (in advance).

The second method should be used when the element name is not statically known and should be generated with the <xsl:element> command.

+6
source share

Use curly braces:

 <input type="rad" name="RadGroup" value="{productOptionInfo}" /> 
+3
source share

You can use single quotes inside and double quotes outside or vice versa.

In addition, the XML specification says:

In order for attribute values ​​to contain both single and double quotes, an apostrophe or a single quote character ( ' ) can be represented as " &apos; ", and a double-quote character (") can be represented by &quot; "

0
source share

All Articles