This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Accessing URL Parameters In A XSLT Page


Hi Haeko,

> I'm having problems using xslt to access the parameters sent in a
> URL. This is the URL that calls the my customer login xslt page, in
> this page I wanted to read some parameters from the calling URL add
> a name parameter and forward it to another page...

You can only get access to the parameters from the URL if you are
using a server-side framework such as Cocoon or XSQL. I guess from the
fact that you have xmlns:xsql="urn:oracle-xsql" in your XML page that
you're using XSQL?

The syntax {@AId} for inserting the value of the AId parameter only
works within an xsql:query, I think. You can include the value of a
parameter that you specify in the URL within the XML that's passed to
the XSLT stylesheet using the xsql:include-param element as follows:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" media="Mozilla"
                 href="ticketreservHTML.xsl"?>
<index xmlns:xsql="urn:oracle-xsql">
  ...
  <form action="/ticket/ticketresv.xsql" method="get">
    <field name="AId" type="hiddenField">
      <value><xsql:include-param name="AId" /></value>
    </field>
    ...
  </form>
</index>

This inserts an element named after the parameter, whose value is the
value of the parameter, into the XML document. If AId is set to 2,
then the XML that the XSLT stylesheet sees will look like:

<index>
  ...
  <form action="/ticket/ticketresv.xsql" method="get">
    <field name="AId" type="hiddenField">
      <value><AId>2</AId></value>
    </field>
    ...
  </form>
</index>

You could transform the field elements into input fields with
something like:

<xsl:template match="field">
  <input name="{@name}" value="{value}" />
</xsl:template>

An alternative method of approaching the problem would be to pass the
values of the request parameters set with the URL into the stylesheet
as stylesheet parameters. To do that, you need to include an
xsql:set-stylesheet-param element in the XSQL page and leave the
fields empty:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" media="Mozilla"
                 href="ticketreservHTML.xsl"?>
<index xmlns:xsql="urn:oracle-xsql">
  <xsql:set-stylesheet-param name="AId" value="{@AId}" />
  ...
  <form action="/ticket/ticketresv.xsql" method="get">
    <field name="AId" type="hiddenField" />
    ...
  </form>
</index>

Then you need to declare the $AId stylesheet parameter in the XSLT
stylesheet in a top-level element with:

<xsl:param name="AId" />

The templates would then have to match specific field elements and
insert the appropriate parameter into the value attribute of the input
field they generate, for example:

<xsl:template match="field[@name = 'AId']">
  <input name="AId" value="{$AId}" />
</xsl:template>

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]