XSLT Tag - Hidden Input Form Fields

Posted on 2005-02-25
Medium Priority
Last Modified: 2013-11-19

If I have an XML file with multiple criteria (namely, Lastname, Insurance, Language):

<Name>Empire Health</Name>

How would I be able to submit all these values as hidden input form fields in my XSLT?

I am already sending in SessionID:

<input type="hidden" name="SessionID" value="{@SessionID}">

and a single Search Criterion:

<input type="hidden" name="{Params/Criteria/Criterion/Type}" value="{Params/Criteria/Criterion/Type}">

I fear I am missing the situation where multiple search criteria are within the XML and will not be returned. .. How would I iterate between all the values within the Criterion, so as to not miss sending those Criterion values in?

Any advice or guidance is greatly appreciated!

Best regards,
Question by:jmc430
  • 2

Author Comment

ID: 13407511
Slight correction, the single search criterion i am sending is:

<input type="hidden" name="{Params/Criteria/Criterion/Type}" value="{Params/Criteria/Criterion/Name}">

Author Comment

ID: 13407869
This is what I have so far:

<xsl:if test="count(Params/Criteria/Criterion) >0">
<xsl:for-each select="Params/Criteria/Criterion">
<xsl:if test="Name/text()">

<input type="hidden" value="{Params/Criteria/Criterion/Name}" name="{Params/Criteria/Criterion/Type}"></input>

and for testing purposes (to print out what's in the XML) <xsl:value-of select="Name"></xsl:Value-of>


What am I doing wrong?

LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 800 total points
ID: 13408085
Something like this should do the trick:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="html" encoding="iso-8859-1" />

    <xsl:template match="Params">
        <xsl:apply-templates />

    <xsl:template match="Criterion">
        <xsl:element name="input">
            <xsl:attribute name="type">hidden</xsl:attribute>
            <xsl:attribute name="name"><xsl:value-of select="Type" /></xsl:attribute>
            <xsl:attribute name="value"><xsl:value-of select="Name" /></xsl:attribute>


Hope this helps.
LVL 26

Accepted Solution

rdcpro earned 1200 total points
ID: 13408847
Or just fix the XPath:

<input type="hidden" value="{Name}" name="{Type}"></input>

When you do something like:

<xsl:for-each select="Params/Criteria/Criterion">

you're changing the context inside the for-each, so now your XPath expressions should be relative to the current Criterion node.

Mike Sharp

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question