Newbie - Using "<xsl:value-of" as an attribute.

L

Larry Lindstrom

Hello Experts:

I'm learning XML, and I don't understand how to
make this work.

The user sees a grid of radio buttons and labels.
The XSL file has an <html> table of the following:

<td>
<input type="radio"
name="SELECTED_PRODUCT_CODE"
value="<xsl:value-of select='product_code'/>"
/>
<xsl:value-of select="product_name"/>
</td>

As I'm sure is obvious to all of you, Mozilla
complains about the value= statement.

XML Parsing Error: not well-formed
value="<xsl:value-of select='product_code'/>"
----------------------^

Internet Explorer is not as specific, but it
also fails.

I've tried several variations on the above.
I've looked at Google archivesbut, but I can't
compose a query that will find what I need.
I can't figure out what I'm doing wrong.

This is a little self education, my goal for
today is to get the selected product code back
to the server.

Thanks
 
B

Bruno Desthuilliers

Larry said:
Hello Experts:

I'm learning XML, and I don't understand how to
make this work.

The user sees a grid of radio buttons and labels.
The XSL file has an <html> table of the following:

<td>
<input type="radio"
name="SELECTED_PRODUCT_CODE"
value="<xsl:value-of select='product_code'/>"
/>


here you want :

<td>
<xsl:element name="radio">
<xsl:attribute name="name">
SELECTED_PRODUCT_CODE
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select='product_code'/>
</xsl:attribute>
</xsl:element>
<xsl:value-of select="product_name"/>
</td>

(does this answer makes me an 'Expert' ?-)

HTH
Bruno
 
L

Larry Lindstrom

Bruno said:
here you want :

<td>
<xsl:element name="radio">
<xsl:attribute name="name">
SELECTED_PRODUCT_CODE
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select='product_code'/>
</xsl:attribute>
</xsl:element>
<xsl:value-of select="product_name"/>
</td>

(does this answer makes me an 'Expert' ?-)

Thanks Bruno:

I have no doubt that you are an expert.

However radio buttons were not displayed.

So, inspired by your reply, I tried:

<td>
<input type="radio"
name="SELECTED_PRODUCT_CODE" >
<xsl:attribute name="value">
<xsl:value-of select='product_code'/>
</xsl:attribute>
</input>
<xsl:value-of select="product_name"/>
</td>

Both IE and Mozilla now display the radio buttons.

The proof, of course, is getting the product code
back to my server.

I've skimmed through w3school's XML tutorials,
now I'm going back and I'm attempting to apply those
lessons to this simple, but original, project. A
real project, even if it's as simple as this, is the
best way for me to grasp the concepts.

I'm fascinated by all the identifiers you put after
"<xsl:".

I like w3schools' tutorials, but they get a little
thin on "work along with the text" examples about half
way through the XML related topics. And they are more
Microsoft oriented than I would like. Can you
recommend any others?

I built a C++ CGI/Javascript/HTML order entry system
a few years ago, and now I'm trying to drag myself
out of the last century.

I appreciate your response. But I had to think
to get the dots connected. Please don't make me
do that again. : )

Thanks
Larry
 
B

Bruno Desthuilliers

Larry said:
(snip)



Thanks Bruno:

I have no doubt that you are an expert.

You should...
However radio buttons were not displayed.

Of course, I typed too fast and wrote something horrible :(

The good version is :

<td>
<xsl:element name="input">
<xsl:attribute name="type">radio</xsl:attribute>
<xsl:attribute name="name">
SELECTED_PRODUCT_CODE
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select='product_code'/>
</xsl:attribute>
</xsl:element>
So, inspired by your reply, I tried:

<td>
<input type="radio"
name="SELECTED_PRODUCT_CODE" >
<xsl:attribute name="value">
<xsl:value-of select='product_code'/>
</xsl:attribute>
</input>
<xsl:value-of select="product_name"/>
</td>

Both IE and Mozilla now display the radio buttons.

The proof, of course, is getting the product code
back to my server.

So you learn me something.
I didn't think such a code could work - but I'm an almost newbie in
XSLT, so... (and now who is the expert ? you ?-)

(snip)
I like w3schools' tutorials, but they get a little
thin on "work along with the text" examples about half
way through the XML related topics. And they are more
Microsoft oriented than I would like. Can you
recommend any others?

Not really a tutorial, but something that you may want to have in your
favs if you work on XSLT :

http://www.zvon.org/xxl/XSLTreference/Output/

Bruno
 
L

Larry Lindstrom

Bruno Desthuilliers wrote:

<td>
<xsl:element name="input">
<xsl:attribute name="type">radio</xsl:attribute>
<xsl:attribute name="name">
SELECTED_PRODUCT_CODE
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select='product_code'/>
</xsl:attribute>
</xsl:element>
<xsl:value-of select="product_name"/>

< Snip >

Thanks again Bruno:

As an experienced C++ user, but not an expert, I often
see inexperienced users doing things that might save a few
keystrokes, but produce code that is hard to understand or
debug.

It's obvious that your use of xsl statements throughout
your example requires more keystrokes type.

What are the advantages of using the longer form of
these XSL statements?

Thanks
Larry
 
P

Patrick TJ McPhee

% <td>
% <input type="radio"
% name="SELECTED_PRODUCT_CODE"
% value="<xsl:value-of select='product_code'/>"
% />
% <xsl:value-of select="product_name"/>
% </td>


<xsl:attribute does what you want, but you can also use something
closer to your first attempt:

% <td>
% <input type="radio"
% name="SELECTED_PRODUCT_CODE"
value="{product_code}"
% />
% <xsl:value-of select="product_name"/>
% </td>


The "{}" notation will work for attributes in the output result tree
and for some attributes of XSLT elements (for instance, the `name'
attribute of xsl:attribute). It's called an attribute value template,
and any XPath expression can go between the braces.
 
B

Bruno Desthuilliers

Larry said:
Bruno Desthuilliers wrote:




< Snip >

Thanks again Bruno:

As an experienced C++ user, but not an expert, I often
see inexperienced users doing things that might save a few
keystrokes, but produce code that is hard to understand or
debug.

It's obvious that your use of xsl statements throughout
your example requires more keystrokes type.

What are the advantages of using the longer form of
these XSL statements?

As an inexperimented XSLT user, and certainly not an expert, the answer
I can give is that I just didn't know the way you did it could work...

Any XSLT guru around ?

Bruno
 
L

Larry Lindstrom

Patrick said:
% <td>
% <input type="radio"
% name="SELECTED_PRODUCT_CODE"
% value="<xsl:value-of select='product_code'/>"
% />
% <xsl:value-of select="product_name"/>
% </td>

<xsl:attribute does what you want, but you can also use something
closer to your first attempt:

% <td>
% <input type="radio"
% name="SELECTED_PRODUCT_CODE"
value="{product_code}"
% />
% <xsl:value-of select="product_name"/>
% </td>

The "{}" notation will work for attributes in the output result tree
and for some attributes of XSLT elements (for instance, the `name'
attribute of xsl:attribute). It's called an attribute value template,
and any XPath expression can go between the braces.

Thanks Patrick:

Mozilla displays the "catalog" properly with your
suggestion. However, I haven't been able to find a
reference that describes this construct.

I've been working a new set of tutorials on the
page Bruno pointed at, so I haven't moved forward
to xforms, which I hope will allow me to send this
information to my server.

Is there a way to examine the XSLT output, or the
DOM, with Mozilla? I'm getting nothing on this page
with Mozilla's DOM inspector.

Thanks
Larry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top