473,886 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.x sl"?>
<NEXXML xmlns:sql="urn: schemas-microsoft-com:xml-sql">
<columns/>
<rows>
<row SAPVendorRef="1 5001" VendorName="A&q uot; A Meats" EntityId="3021"
rsposition="1"/>
<row SAPVendorRef="5 7232" VendorName="Abb eyhouse Foods" EntityId="3050"
rsposition="2"/>
<row SAPVendorRef="1 5011" VendorName="Ale xandra Rentals" EntityId="3023"
rsposition="3"/>
<row SAPVendorRef="1 0184" VendorName="Ale xandra Workwear PLC"
EntityId="3014" rsposition="4"/>
<row SAPVendorRef="1 5012" VendorName="All ied Bakeries NI" EntityId="3024"
rsposition="5"/>
<row SAPVendorRef="6 0143" VendorName="Ast ron On Line" EntityId="3056"
rsposition="6"/>
<row SAPVendorRef="5 6531" VendorName="Bac kgammo'n" EntityId="3048"
rsposition="7"/>
<row SAPVendorRef="1 5062" VendorName="Bri tish Bakeries NI" EntityId="3025"
rsposition="8"/>
</rows>
</NEXXML>

The XSLT Document

<xsl:styleshe et 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,&qu ot;abcdefghijkl mnopqrstuvwxyz& quot;,&quot;ABC DEFGHIJKLMNOPQR S
TUVWXYZ&quot;), translate(&quot ;A&quot;,&quot; abcdefghijklmno pqrstuvwxyz&quo t
;,&quot;ABCDEFG HIJKLMNOPQRSTUV WXYZ&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,&qu ot;abcdefghijkl mnopqrstuvwxyz& quot;,&quot;ABC DEFGHIJKLMNOPQR S
TUVWXYZ&quot;), translate(&quot ;A&quot;,&quot; abcdefghijklmno pqrstuvwxyz&quo t
;,&quot;ABCDEFG HIJKLMNOPQRSTUV WXYZ&quot;)) ]">
<xsl:copy-of select="."/>

changes to:

<xsl:template match="row[ starts-with(translate(
@VendorName,&qu ot;abcdefghijkl mnopqrstuvwxyz& quot;,&quot;ABC DEFGHIJKLMNOPQR S
TUVWXYZ&quot;), translate(&quot ;A&quot;&quot;, &quot;abcdefghi jklmnopqrstuvwx y
z&quot;,&quot;A BCDEFGHIJKLMNOP QRSTUVWXYZ&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 8070
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,'ab cdefghijklmnopq rstuvwxyz','A
BCDEFGHIJKLMNOP QRSTUVWXYZ'),tr anslate('A&quot ;','abcdefghijk lmnopqrstuvwxyz '
,'ABCDEFGHIJKLM NOPQRSTUVWXYZ') )]">

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:styleshe et 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="transla te($search-for,'abcdefghij klmnopqrstuvwxy z','ABCDEFGHIJK LMNOP
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,'ab cdefghijklmnopq rstuvwxyz','
ABCDEFGHIJKLMNO PQRSTUVWXYZ'),$ 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.fsn et.co.uk> wrote in message
news:bd******** **@news7.svr.po l.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.x sl"?>
<NEXXML xmlns:sql="urn: schemas-microsoft-com:xml-sql">
<columns/>
<rows>
<row SAPVendorRef="1 5001" VendorName="A&q uot; A Meats" EntityId="3021"
rsposition="1"/>
<row SAPVendorRef="5 7232" VendorName="Abb eyhouse Foods" EntityId="3050"
rsposition="2"/>
<row SAPVendorRef="1 5011" VendorName="Ale xandra Rentals" EntityId="3023"
rsposition="3"/>
<row SAPVendorRef="1 0184" VendorName="Ale xandra Workwear PLC"
EntityId="3014" rsposition="4"/>
<row SAPVendorRef="1 5012" VendorName="All ied Bakeries NI" EntityId="3024"
rsposition="5"/>
<row SAPVendorRef="6 0143" VendorName="Ast ron On Line" EntityId="3056"
rsposition="6"/>
<row SAPVendorRef="5 6531" VendorName="Bac kgammo'n" EntityId="3048"
rsposition="7"/>
<row SAPVendorRef="1 5062" VendorName="Bri tish Bakeries NI" EntityId="3025"
rsposition="8"/>
</rows>
</NEXXML>

The XSLT Document

<xsl:styleshe et 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,&qu ot;abcdefghijkl mnopqrstuvwxyz& quot;,&quot;ABC DEFGHIJKLMNOPQR S TUVWXYZ&quot;), translate(&quot ;A&quot;,&quot; abcdefghijklmno pqrstuvwxyz&quo t ;,&quot;ABCDEFG HIJKLMNOPQRSTUV WXYZ&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,&qu ot;abcdefghijkl mnopqrstuvwxyz& quot;,&quot;ABC DEFGHIJKLMNOPQR S TUVWXYZ&quot;), translate(&quot ;A&quot;,&quot; abcdefghijklmno pqrstuvwxyz&quo t ;,&quot;ABCDEFG HIJKLMNOPQRSTUV WXYZ&quot;)) ]">
<xsl:copy-of select="."/>

changes to:

<xsl:template match="row[ starts-with(translate(
@VendorName,&qu ot;abcdefghijkl mnopqrstuvwxyz& quot;,&quot;ABC DEFGHIJKLMNOPQR S TUVWXYZ&quot;), translate(&quot ;A&quot;&quot;, &quot;abcdefghi jklmnopqrstuvwx y z&quot;,&quot;A BCDEFGHIJKLMNOP QRSTUVWXYZ&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
3275
by: usr2003 | last post by:
I wrote the following test program to test the linkage directives extern "C": #include <stdio.h> extern "C" {
4
2508
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
20549
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
14825
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 expression: .... snip ...
5
3452
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; &lt;me@mydomain.com&gt;</Address> </Addresses>
2
1633
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 = "http://www.myserver.com?id=123&name=HomerSimpson";
42
3481
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: ---------------------------------------------------- TypeError: addFile() takes exactly 1 argument (2 given) ----------------------------------------------------
14
5945
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 because of this, so I hope some of you gurus can enlighten me with this :) In what circumstances can the "&amp;" in the source code be involuntary changed to "&" by a browser when or other software, when editing and uploading the file to the web...
3
3108
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 =server.createobject("ADODB.connection") objConn.open "DSN=Photo" Dim sqlSELsite,ObjRSSel sqlSELsite = "SELECT Name FROM tblbwday WHERE B'day ="& date() &" " '
0
9799
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10872
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10429
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7139
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5808
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6010
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4627
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.