xsl-list
[Top] [All Lists]

Re: Using xsl:value-of select in a form input textbox

2004-03-11 16:25:43
Hi Anne,

At 05:27 PM 3/11/2004, you wrote:
Hi,

I am new to XSLT and am trying to parse an XML string containing a phone
number into 3 strings - the area, prefix, and suffix.  (This XML string is
coming from a database.)  I want to display the substrings in separate
textboxes.   Here is what I have so far:

<!-- THIS CURRENTLY PUTS THE ENTIRE EVENINGPHONE IN THE TEXTBOX -->
<!-- WHICH I DO NOT WANT -->
<input type="text" name="txtHPhone" size="20" maxlength="10"
value="{UPDATEADDRESS/RECEIVER/ADDRESS/EVENINGPHONE}" />

This uses an Attribute Value Template (the brackets) to tell the processor to interpret the string inside as XPath, and evaluate it.

You can do exactly this but also include the substringing operations you are already doing elsewhere:

<!-- THIS SUCCESSFULLY DISPLAYS THE AREA  OF EVENINGPHONE -->
<xsl:value-of
select="substring(UPDATEADDRESS/RECEIVER/ADDRESS/EVENINGPHONE,1,3)" />

so ...

<!-- INSTEAD, WHAT value WOULD GO IN HERE: -->
<input type="text" name="txtHPhoneAREA" size="20" maxlength="10" value="" />

...you would try

<input type="text" name="txtHPhoneAREA" size="20" maxlength="10"
  value="{substring(UPDATEADDRESS/RECEIVER/ADDRESS/EVENINGPHONE,1,3)}" />

...although the code would be cleaner if you could contrive it in such a way that the EVENINGPHONE node you are after were the context node of the expression. (You could do this by emitting the result <input> node inside a template matching the EVENINGPHONE, for example.) In that case the result element in your stylesheet would look something like:

<input type="text" name="txtHPhoneAREA" size="20" maxlength="10"
  value="{substring(.,1,3)}" />

...because the XPath '.' (short for 'self::node()') would then refer to the EVENINGPHONE itself.

I hope that helps. Ask again for any clarifications.

Cheers,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>