You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by Rick Bullotta <ri...@lighthammer.com> on 2004/04/06 16:33:15 UTC

Issue with JSTL xml taglib when accessing node attribute

We're discovering some fairly significant limitations with the xml taglib
when dealing with node values, particularly attribute values...

 

Given the following xml:

 

<Data>

            <Metadata>

                        <Column Name="ABC" Type="1"/>          

                        <Column Name="CDE" Type="2"/>          

            </Metadata>

            <DataRow>

                        <ABC>XXX</ABC>

                        <CDE>123</CDE>

            </DataRow>

            <DataRow>

                        <ABC>YYY</ABC>

                        <CDE>234</CDE>

            </DataRow>

            <DataRow>

                        <ABC>ZZZ</ABC>

                        <CDE>345</CDE>

            </DataRow>

</Data>

 

And the following JSP (this was pseudo-coded from the real thing):

 

The goal is to iterate through the rows and columns, and based on the
column's metadata type (which can easily be derived via Xpath and the column
name), output data accordingly..

 

<c:import var="docString" url="Thing.xml"/>

<x:parse var="document" doc="${docString}"/>

 

<x:forEach select="$document/Data/DataRow" var="RowDetail"
varStatus="RowNo">

            <x:forEach select="$RowDetail/*" var="ColumnDetail">

                        <x:set var="ColumnName" select="name(.)"/>

                        <x:set var="ColumnType"
select="../../Metadata/Column[@Name = $ColumnName]"/>

 

<c:if test="${ColumnType == '1'}>

                                    Do Something for type 1.

</c:if>

 

<c:if test="${ColumnType == '2'}>

                                    Do Something for type 2.

</c:if>

            </x:forEach>

</x:forEach>

 

Bottom line is we need to place the value of the xml node's attribute into a
variable that can later be used in comparisons, as in the above example, and
there does not appear to be a way to do so.

 

We've also tried using the following in lieu of the c:if tags, to no avail:

 

                        <x:if select="../../Metadata/Column[@Name =
$ColumnName][@Type == '1']">

                                    Do something for type 1

                        </x:if>

 

                        <x:if select="../../Metadata/Column[@Name =
$ColumnName][@Type == '2']">

                                    Do something for type 2

                        </x:if>

 

Is there a way to "scalar-ize" (new word! <g>) the results of an x:set.  If
you do a c:out on an attribute node selected using x:set, it is treated as
the string:

 

[Type = "1"]

 

..,not simply 1

 

Any recommendations welcomed!

 

- Rick

 

 

 

 


RE: Encoded string values in URL for import tag

Posted by Rick Bullotta <ri...@lighthammer.com>.
Thanks, Martin.  Works like a charm.  I was surprised that the "inlined"
approach didn't work (I suspected that the + and % characters were being
treated as arithmetic operators by the EL processor), and started to make my
way through the source code, but you saved me the effort.  When I have time,
I'll try to sleuth out why the two behaviors are different.

- Rick

-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Martin Cooper
Sent: Tuesday, April 06, 2004 3:14 PM
To: taglibs-dev@jakarta.apache.org
Subject: Re: Encoded string values in URL for import tag

Try this instead:

  <c:import var="docString" url="http://localhost/servlet/MyServlet">
    <c:param name="MyParam" value="${param.TheParam}"/>
  </c:import>

--
Martin Cooper


"Rick Bullotta" <ri...@lighthammer.com> wrote in message
news:200404061853.OAA02852@tonnant.nxlkhost.com...
> The following tag usage fails if the request parameter "TheParam" has HTML
> encoded values in it:
>
>
>
> <c:import var="docString"
> url="http://localhost/servlet/MyServlet?MyParam=${param.TheParam}"/>
>
>
>
> If the JSP page is called with something such as:
>
>
>
> http://MyWebApp/MyPage.jsp?TheParam=This%20Or%20That
>
>
>
> or
>
>
>
> http://MyWebApp/MyPage.jsp?TheParam=This+Or+That
>
>
>
> ...an exception is thrown.
>
>
>
> Any insights?  Any way to embed encoded values in the url attribute in a
> dynamic manner?
>
>
>
> Thanks!
>
>
>
> - Rick
>
>




---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org


Re: Encoded string values in URL for import tag

Posted by Martin Cooper <ma...@apache.org>.
Try this instead:

  <c:import var="docString" url="http://localhost/servlet/MyServlet">
    <c:param name="MyParam" value="${param.TheParam}"/>
  </c:import>

--
Martin Cooper


"Rick Bullotta" <ri...@lighthammer.com> wrote in message
news:200404061853.OAA02852@tonnant.nxlkhost.com...
> The following tag usage fails if the request parameter "TheParam" has HTML
> encoded values in it:
>
>
>
> <c:import var="docString"
> url="http://localhost/servlet/MyServlet?MyParam=${param.TheParam}"/>
>
>
>
> If the JSP page is called with something such as:
>
>
>
> http://MyWebApp/MyPage.jsp?TheParam=This%20Or%20That
>
>
>
> or
>
>
>
> http://MyWebApp/MyPage.jsp?TheParam=This+Or+That
>
>
>
> ...an exception is thrown.
>
>
>
> Any insights?  Any way to embed encoded values in the url attribute in a
> dynamic manner?
>
>
>
> Thanks!
>
>
>
> - Rick
>
>




---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org


RE: Issue with JSTL xml taglib when accessing node attribute

Posted by Rick Bullotta <ri...@lighthammer.com>.
FYI, we've found a solution with some experimentation, notably using the
Xpath string and number functions as needed to "scalar-ize" the values...

 

Replacing:

 

<x:set var="ColumnType" select="../../Metadata/Column[@Name =
$ColumnName]"/>

 

.with.

 

<x:set var="ColumnType" select="number(../../Metadata/Column[@Name =
$ColumnName])"/>

 

Did the trick.

 

Good example for the FAQ.  What's the best way to write something up for the
FAQ and submit it?

 

- Rick

 

-----Original Message-----
From: Rick Bullotta [mailto:rick.bullotta@lighthammer.com] 
Sent: Tuesday, April 06, 2004 10:33 AM
To: taglibs-dev@jakarta.apache.org
Subject: Issue with JSTL xml taglib when accessing node attribute

 

We're discovering some fairly significant limitations with the xml taglib

when dealing with node values, particularly attribute values...

 

 

 

Given the following xml:

 

 

 

<Data>

 

            <Metadata>

 

                        <Column Name="ABC" Type="1"/>          

 

                        <Column Name="CDE" Type="2"/>          

 

            </Metadata>

 

            <DataRow>

 

                        <ABC>XXX</ABC>

 

                        <CDE>123</CDE>

 

            </DataRow>

 

            <DataRow>

 

                        <ABC>YYY</ABC>

 

                        <CDE>234</CDE>

 

            </DataRow>

 

            <DataRow>

 

                        <ABC>ZZZ</ABC>

 

                        <CDE>345</CDE>

 

            </DataRow>

 

</Data>

 

 

 

And the following JSP (this was pseudo-coded from the real thing):

 

 

 

The goal is to iterate through the rows and columns, and based on the

column's metadata type (which can easily be derived via Xpath and the column

name), output data accordingly..

 

 

 

<c:import var="docString" url="Thing.xml"/>

 

<x:parse var="document" doc="${docString}"/>

 

 

 

<x:forEach select="$document/Data/DataRow" var="RowDetail"

varStatus="RowNo">

 

            <x:forEach select="$RowDetail/*" var="ColumnDetail">

 

                        <x:set var="ColumnName" select="name(.)"/>

 

                        <x:set var="ColumnType"

select="../../Metadata/Column[@Name = $ColumnName]"/>

 

 

 

<c:if test="${ColumnType == '1'}>

 

                                    Do Something for type 1.

 

</c:if>

 

 

 

<c:if test="${ColumnType == '2'}>

 

                                    Do Something for type 2.

 

</c:if>

 

            </x:forEach>

 

</x:forEach>

 

 

 

Bottom line is we need to place the value of the xml node's attribute into a

variable that can later be used in comparisons, as in the above example, and

there does not appear to be a way to do so.

 

 

 

We've also tried using the following in lieu of the c:if tags, to no avail:

 

 

 

                        <x:if select="../../Metadata/Column[@Name =

$ColumnName][@Type == '1']">

 

                                    Do something for type 1

 

                        </x:if>

 

 

 

                        <x:if select="../../Metadata/Column[@Name =

$ColumnName][@Type == '2']">

 

                                    Do something for type 2

 

                        </x:if>

 

 

 

Is there a way to "scalar-ize" (new word! <g>) the results of an x:set.  If

you do a c:out on an attribute node selected using x:set, it is treated as

the string:

 

 

 

[Type = "1"]

 

 

 

..,not simply 1

 

 

 

Any recommendations welcomed!

 

 

 

- Rick

 

 

 

 

 

 

 

 

 


Encoded string values in URL for import tag

Posted by Rick Bullotta <ri...@lighthammer.com>.
The following tag usage fails if the request parameter "TheParam" has HTML
encoded values in it:

 

<c:import var="docString"
url="http://localhost/servlet/MyServlet?MyParam=${param.TheParam}"/>

 

If the JSP page is called with something such as:

 

http://MyWebApp/MyPage.jsp?TheParam=This%20Or%20That

 

or 

 

http://MyWebApp/MyPage.jsp?TheParam=This+Or+That

 

...an exception is thrown.

 

Any insights?  Any way to embed encoded values in the url attribute in a
dynamic manner?

 

Thanks!

 

- Rick