Accessing the value of an input element with XPath in an XSLT
Posted
by asymmetric
on Stack Overflow
See other posts from Stack Overflow
or by asymmetric
Published on 2010-04-14T15:41:52Z
Indexed on
2010/04/14
15:43 UTC
Read the original article
Hit count: 236
Hi!
I'm developing a web app that has a button that triggers an XSLT transformation of the document DOM, with a stylesheet fetched via AJAX.
Here's a portion of the HTML:
<html>
<head>
<title>Static Javascript-based XMR Form Creator</title>
</head>
<body>
<h1 id="title">Static Javascript-based XMR Form Creator</h1>
<div class="opt_block" id="main_opts">
Form name <input type="text" id="form_name" />
Form cols <input type="text" id="form_cols" size="3" maxlength="3" />
</div>
<button id="generate">Generate source</button>
<textarea rows="20" cols="50" id="xmr_source" ></textarea>
</body>
Inside the stylesheet, I want to access the value
attribute of the first input field, the one with id form_name
.
The XSLT looks like this:
<xsl:template match="/html/body/div[@id = 'main_opts']" >
<form>
<xsl:attribute name="fname">
<xsl:value-of select="input[@id = 'form_name']/@value" />
</xsl:attribute>
</form>
</xsl:template>
The problem is that the XPath that should do the work:
<xsl:value-of select="input[@id = 'form_name']/@value" />
returns nothing.
Can anyone help?
© Stack Overflow or respective owner