472,791 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 software developers and data experts.

Question on " inside function arguments

Hi

I have an XML documnet and a XSLT document as shown below

THe XSLT document brings back a filtered docmument that has the VendorName
that starts with a particular sub-string
This works as expected with alphabet and number characters and the ' (single
quote ' entity) character but does not work if a double quote character
" is part of the string to filter on
This returns all Vendor Names that begin with A (either case)

The XML Document

<?xml-stylesheet type="text/xsl" href="C:\XSL1.xsl"?>
<NEXXML xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<columns/>
<rows>
<row SAPVendorRef="15001" VendorName="A&quot; A Meats" EntityId="3021"
rsposition="1"/>
<row SAPVendorRef="57232" VendorName="Abbeyhouse Foods" EntityId="3050"
rsposition="2"/>
<row SAPVendorRef="15011" VendorName="Alexandra Rentals" EntityId="3023"
rsposition="3"/>
<row SAPVendorRef="10184" VendorName="Alexandra Workwear PLC"
EntityId="3014" rsposition="4"/>
<row SAPVendorRef="15012" VendorName="Allied Bakeries NI" EntityId="3024"
rsposition="5"/>
<row SAPVendorRef="60143" VendorName="Astron On Line" EntityId="3056"
rsposition="6"/>
<row SAPVendorRef="56531" VendorName="Backgammo'n" EntityId="3048"
rsposition="7"/>
<row SAPVendorRef="15062" VendorName="British Bakeries NI" EntityId="3025"
rsposition="8"/>
</rows>
</NEXXML>

The XSLT Document

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<xsl:output method="xml"/>
<xsl:template match="/">
<NEXXML>
<rows>
<xsl:apply-templates/>
</rows>
</NEXXML>
</xsl:template>
<xsl:template match="rows">
<xsl:apply-templates select="row"/>
</xsl:template>
<xsl:template match="row[ starts-with(translate(
@VendorName,&quot;abcdefghijklmnopqrstuvwxyz&quot; ,&quot;ABCDEFGHIJKLMNOPQRS
TUVWXYZ&quot;),translate(&quot;A&quot;,&quot;abcde fghijklmnopqrstuvwxyz&quot
;,&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;)) ]">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

If I want to search on the string A" the line

<xsl:template match="row[ starts-with(translate(
@VendorName,&quot;abcdefghijklmnopqrstuvwxyz&quot; ,&quot;ABCDEFGHIJKLMNOPQRS
TUVWXYZ&quot;),translate(&quot;A&quot;,&quot;abcde fghijklmnopqrstuvwxyz&quot
;,&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;)) ]">
<xsl:copy-of select="."/>

changes to:

<xsl:template match="row[ starts-with(translate(
@VendorName,&quot;abcdefghijklmnopqrstuvwxyz&quot; ,&quot;ABCDEFGHIJKLMNOPQRS
TUVWXYZ&quot;),translate(&quot;A&quot;&quot;,&quot ;abcdefghijklmnopqrstuvwxy
z&quot;,&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;)) ]">
<xsl:copy-of select="."/>

I now get an error Expected token ')' found 'STRING'

From what I can see, this is because the XML parser reads the translate
function intereprets the 1st &quot; as the start of the first argument and
interprets the 2nd &quot; as the end of the 1st argument, instead of being
part of the first argument and then expects a comma (,) and the second
string argument

How I can make the parser take the 2nd quote as part of the first string
argument if there is a quote in the 1st argument
I know I could probably do this by replacing the double quotes with single
quotes but then I am assumming I will get the same problem with single
quotes been part of the literal string.

Your help is greatly appreciated. Thanks in advance

Regards David Furey

Jul 20 '05 #1
1 7987
Hi David,

In XPath strings can be delimited by either single (&apos;) or double
(&quot;) marks. So your template could read...

<xsl:template
match="row[starts-with(translate(@VendorName,'abcdefghijklmnopqrstuv wxyz','A
BCDEFGHIJKLMNOPQRSTUVWXYZ'),translate('A&quot;','a bcdefghijklmnopqrstuvwxyz'
,'ABCDEFGHIJKLMNOPQRSTUVWXYZ'))]">

Although using a template match for this is probably quite inefficient. For
two reasons...
i) because you are trying to do things in a template @match you cannot use
variables - which means that for every predicate [] filter evaluation you
are having to uppercase the string being searched for (i.e. that second
translate() call on 'A&quot;').
ii) also, because the filtering is being done at the template match, you are
sending out nodes that you are uninterested in - which are being caught by
the XSLT built-in rule templates (which may mean that if at some point in
the future your <row> elements have any text node children you may end up
with unexpected text in the output).

I assume at some point you are going to parameterize the search - at which
point using template matches for the filtering will become impossible. You
might want to try something like...

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<xsl:output method="xml"/>
<xsl:param name="search-for" select="'a&quot;'"/>
<!-- convert the param to upper case just once -->
<xsl:variable name="uc-search-for"
select="translate($search-for,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOP
QRSTUVWXYZ')"/>

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

<xsl:template match="rows">
<xsl:apply-templates
select="row[starts-with(translate(@VendorName,'abcdefghijklmnopqrstuv wxyz','
ABCDEFGHIJKLMNOPQRSTUVWXYZ'),$uc-search-for)]"/>
</xsl:template>

<xsl:template match="row">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

Which, apart from making the code dynamic, will perform about twice as fast
as your original fixed stylesheet.

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
"David Furey" <da**@furey.fsnet.co.uk> wrote in message
news:bd**********@news7.svr.pol.co.uk...
Hi

I have an XML documnet and a XSLT document as shown below

THe XSLT document brings back a filtered docmument that has the VendorName
that starts with a particular sub-string
This works as expected with alphabet and number characters and the ' (single quote &apos; entity) character but does not work if a double quote character " is part of the string to filter on
This returns all Vendor Names that begin with A (either case)

The XML Document

<?xml-stylesheet type="text/xsl" href="C:\XSL1.xsl"?>
<NEXXML xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<columns/>
<rows>
<row SAPVendorRef="15001" VendorName="A&quot; A Meats" EntityId="3021"
rsposition="1"/>
<row SAPVendorRef="57232" VendorName="Abbeyhouse Foods" EntityId="3050"
rsposition="2"/>
<row SAPVendorRef="15011" VendorName="Alexandra Rentals" EntityId="3023"
rsposition="3"/>
<row SAPVendorRef="10184" VendorName="Alexandra Workwear PLC"
EntityId="3014" rsposition="4"/>
<row SAPVendorRef="15012" VendorName="Allied Bakeries NI" EntityId="3024"
rsposition="5"/>
<row SAPVendorRef="60143" VendorName="Astron On Line" EntityId="3056"
rsposition="6"/>
<row SAPVendorRef="56531" VendorName="Backgammo'n" EntityId="3048"
rsposition="7"/>
<row SAPVendorRef="15062" VendorName="British Bakeries NI" EntityId="3025"
rsposition="8"/>
</rows>
</NEXXML>

The XSLT Document

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<xsl:output method="xml"/>
<xsl:template match="/">
<NEXXML>
<rows>
<xsl:apply-templates/>
</rows>
</NEXXML>
</xsl:template>
<xsl:template match="rows">
<xsl:apply-templates select="row"/>
</xsl:template>
<xsl:template match="row[ starts-with(translate(
@VendorName,&quot;abcdefghijklmnopqrstuvwxyz&quot; ,&quot;ABCDEFGHIJKLMNOPQRS TUVWXYZ&quot;),translate(&quot;A&quot;,&quot;abcde fghijklmnopqrstuvwxyz&quot ;,&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;)) ]">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

If I want to search on the string A" the line

<xsl:template match="row[ starts-with(translate(
@VendorName,&quot;abcdefghijklmnopqrstuvwxyz&quot; ,&quot;ABCDEFGHIJKLMNOPQRS TUVWXYZ&quot;),translate(&quot;A&quot;,&quot;abcde fghijklmnopqrstuvwxyz&quot ;,&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;)) ]">
<xsl:copy-of select="."/>

changes to:

<xsl:template match="row[ starts-with(translate(
@VendorName,&quot;abcdefghijklmnopqrstuvwxyz&quot; ,&quot;ABCDEFGHIJKLMNOPQRS TUVWXYZ&quot;),translate(&quot;A&quot;&quot;,&quot ;abcdefghijklmnopqrstuvwxy z&quot;,&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;)) ]">
<xsl:copy-of select="."/>

I now get an error Expected token ')' found 'STRING'

From what I can see, this is because the XML parser reads the translate
function intereprets the 1st &quot; as the start of the first argument and
interprets the 2nd &quot; as the end of the 1st argument, instead of being
part of the first argument and then expects a comma (,) and the second
string argument

How I can make the parser take the 2nd quote as part of the first string
argument if there is a quote in the 1st argument
I know I could probably do this by replacing the double quotes with single
quotes but then I am assumming I will get the same problem with single
quotes been part of the literal string.

Your help is greatly appreciated. Thanks in advance

Regards David Furey

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: usr2003 | last post by:
I wrote the following test program to test the linkage directives extern "C": #include <stdio.h> extern "C" {
4
by: Jian H. Li | last post by:
Hello, What's the essential differences between the two ways of "class::member" & "object.member"(or object_pointer->member)? class C{ public: void f() {} int i; };
2
by: Eric Osman | last post by:
Hi, I'm looking for a javascript function that will convert input such as this: <CLUB Code=" into this: &lt;CLUB Code=&quot;
4
by: barney | last post by:
Hello, I' m using .NET System.Xml.XmlDOcument. When I do the following: XmlDocument xml = new XmlDocument(); xml.Load("blah"); .... xml.Save("blub"); I've got the problem that the following...
5
by: martin | last post by:
Hi, I would be extremly grateful for some help on producing an xml fragemt. The fragment that I wish to produce should look like this <Addresses> <Address>&qout;Somebody's Name&quot;...
2
by: Mehdi | last post by:
Hi, I need to pass an URL via a hidden value as follow: <input type="hidden" id="Test" runat="Server"> and on Page_Load I assign a value to this hidden input as follow: Test.Value =...
42
by: Holger | last post by:
Hi guys Tried searching for a solution to this, but the error message is so generic, that I could not get any meaningfull results. Anyways - errormessage:...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
3
by: divya | last post by:
Hi, I have a table tblbwday with 2 fields Name and Birthday.I have written this script for displaying evryday names of the people on that day. <% set objConn...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.