Connecting Tech Pros Worldwide Help | Site Map

XSLT: Transforming HTML Input Element's Values

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 15th, 2007, 05:55 AM
MaggotChild
Guest
 
Posts: n/a
Default XSLT: Transforming HTML Input Element's Values

Hi, I'm trying to transform the values entered into a form:

HTML:

<div id="container">
<div id="bs">
<input id="name" type="text"/>
<p>PPPPP</p>
<a href="#" onclick="return transform()">Do it!</a>
</div>
</div>

XSLT:

<xsl:template match="/">
<strong><xsl:value-of select="//input[@type='text']/@value"/></
strong>
--><xsl:value-of select="//p/text()"/>
</xsl:template>

Java Script:

function transform() {
....

xmlDoc = document.implementation.createDocument("", "", null);
xmlRef = document.getElementById('bs');

var clone = xmlDoc.importNode(xmlRef,true);
xmlDoc.appendChild(clone);

var fragment = xsltProcessor.transformToFragment(xmlDoc, document);

document.getElementById("container").innerHTML = "";
document.getElementById("container").appendChild(f ragment);

....
}

The <pelement gets transformed, but not the input element.
..
Now, I understand that I can pull the values out of the form with Java
Script and simply change the XPath expression to a XSLT param, but why
can't the transformation pull the values directly?

<input type="text" value="grr!"/will transform. Is the tree
structure for these two different? Humm, now that I think about it

document.getElementById('name').value

returns the value, whereas

document.getElementById('name').getAttribute('valu e')

returns null

Any explanations? Is it not possible to transform user supplied values
for input elements without passing the values into the style sheet as
parameters?


  #2  
Old May 15th, 2007, 12:35 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: XSLT: Transforming HTML Input Element's Values

MaggotChild wrote:
Quote:
<input type="text" value="grr!"/will transform. Is the tree
structure for these two different? Humm, now that I think about it
>
document.getElementById('name').value
>
returns the value, whereas
>
document.getElementById('name').getAttribute('valu e')
>
returns null
>
Any explanations? Is it not possible to transform user supplied values
for input elements without passing the values into the style sheet as
parameters?
I do not think it is possible, @value is the attribute value which is
different from the value property of a control as the attribute value
does not change when someone enters text in the control. So the XSLT
processor or the XPath engine does only have access to the attribute
value, not the value property.


--

Martin Honnen
http://JavaScript.FAQTs.com/
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.