473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

escape problem ?

hi,

In a file.xsl I have :

================================================== ====================
....
<xsl:variable name="LANGS" select="path"/>

<xsl:template match="@*|node()">
<xsl:for-each select="$LANGS">
<xsl:value-of select='document("file.xml")/.../title[@lang=$LANGS]'/>
</xsl:for-each>
</xsl:template>
....
================================================== ====================

Everything is ok and tested exept that @lang=$LANGS don't give me all
the values of LANGS. I must put `<xsl:value-of select="."/>' to obtain
them. But it is not accepted. I tried `&lt;xsl:value-of
select="."/&gt;' but it doesn't work too.

What can I do ?

A lot of thanks for any clue
--
ph
Mar 24 '06 #1
6 1375
Impossible to answer without seeing what you're setting LANGS to and
what your input document is.
Mar 24 '06 #2
Fri, 24 Mar 2006 10:55:29 -0500, in comp.text.xml,
Joseph Kesselman wrote :
Impossible to answer without seeing what you're setting LANGS to and
what your input document is.


Ok, the file.xsl is :
================================================== ====================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:variable name="LANGS"
select="//span[not(@xml:lang=preceding::span/
@xml:lang)]/@xml:lang"/>

<xsl:template match="@*|node()">
<xsl:for-each select="$LANGS">
<xsl:value-of select="$filename"/>.<xsl:value-of
select='document("menu.xml")/menu/item[@name=$filename]/
ch[titre=$chapitre]/titre[@lang=$LANGS]'/>.<xsl:value-of
select="."/>
.html
</xsl:for-each>
<xsl:text>&#xa;</xsl:text>
</xsl:template>

</xsl:stylesheet>
================================================== ====================

I apply it to file.xml:

================================================== ====================
<?xml version="1.0" encoding="ISO-8859-1"?>
<body>
<h1>
<span xml:lang="en">Level two. </span>
<span xml:lang="fr">Secondes. </span>
Chapitre : Statistiques</h1>
<h3>1.
Activités : </h3>
<table class="classe" border="1" cellspacing="4"/>
<h3>2.
Cours : </h3>
<table class="classe" border="1" cellspacing="4"/>
<h3>3.
Exercices : </h3>
<table class="classe" border="1" cellspacing="4"/>
<h3>4.
Travaux dirigés : </h3>
<table class="classe" border="1" cellspacing="4"/>
<h3>5.
Baccalauréat : </h3>
<table class="classe" border="1" cellspacing="4"/>
<h3>6.
Figures dynamiques : </h3>
<table class="classe" border="1" cellspacing="4"/>
<h3>7.
Contrôles : </h3>
<table class="classe" border="1" cellspacing="4"/>
<h3>8.
Notes : </h3>
<table class="classe" border="1" cellspacing="4"/>
</body>
================================================== ====================

with the command :
xsltproc -stringparam filename secondes -stringparam chapitre
Statistics file.xsl file.xml

And menu.xml contains :

================================================== ====================
<?xml version="1.0" encoding="ISO-8859-1"?>
<menu>
<item name='index'>
<text lang='en'>Home</text>
<text lang='fr'>Accueil</text>
</item>

<item name='secondes'>
<text lang='en'>Level two</text>
<text lang='fr'>Secondes</text>
<ch>
<titre lang='en'>Numbers and calculators</titre>
<titre lang='fr'>Nombres et calculatrices</titre>
</ch>
<ch>
<titre lang='en'>Functions and problems of first degree</titre>
<titre lang='fr'>Fonctions et problemes du premier degre</titre>
</ch>
<ch>
<titre lang='en'>Circular functions</titre>
<titre lang='fr'>Trigonometrie et fonctions circulaires</titre>
</ch>
<ch>
<titre lang='en'>Statistics</titre>
<titre lang='fr'>Statistiques</titre>
</ch>
<ch>
<titre lang='en'>Visual and computation in 3D</titre>
<titre lang='fr'>Voir et calculer dans l'espace</titre>
</ch>
</menu>
================================================== ====================

the result is :
secondes.Statistics.en.html
secondes.Statistics.fr.html

but I want
secondes.Statistics.en.html
secondes.Statistiques.fr.html
^^^^

Regards
--
ph
Mar 24 '06 #3
First problem: The sample files you gave us are slightly broken.

You really should be declaring the stylesheet parameters.

As you gave it to us, menu.xml is missing an </item>.

And as you've written it, you're putting whitespace into the output
between some of the chunks of text you're trying to assemble. You
probably want to either remove some of the whitespace from your
stylesheet or use <xsl:text> to clearly indicate what literal text is
and isn't meaningful.

But your real question is why
<xsl:value-of
select='document("menu.xml")/menu/item[@name=$filename]/
ch[titre=$chapitre]/titre[@lang=$LANGS]'/>
is generating the same result every time.

The answer's simple: The expression is completely independent of the
values you're iterating over, so it *must* produce the same result every
time. The string value of a nodeset is the string value of the first
node in the nodeset, so you are always testing the first entry in $LANG.

Changing it to [@lang=.] should help.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 25 '06 #4
Le Fri, 24 Mar 2006 19:41:45 -0500,
Dans le forum comp.text.xml,
Joe Kesselman a écrit :
...
Excuse me for giving some mistake in my file (see right ones below in
which long lines are cuted after the 80's character).
But your real question is why
<xsl:value-of
select='document("menu.xml")/menu/item[@name=$filename]/
ch[titre=$chapitre]/titre[@lang=$LANGS]'/>
is generating the same result every time. The answer's simple: The expression is completely independent of the
values you're iterating over, so it *must* produce the same result
every time. The string value of a nodeset is the string value of the
first node in the nodeset, so you are always testing the first entry
in $LANG.

Changing it to [@lang=.] should help.


[@lang=.] don't work. The result is :

secondes..en.html
secondes..fr.html

One solution is to declare a new variable which name is for example
langs just after <xsl:for-each select="$LANGS"> to get the "current
value" of LANGS (like in files below). I don't like this solution but
it works fine. With the following command :

xsltproc -stringparam filename secondes -stringparam chapitre
Statistiques file.xsl file.xml

The results are :

secondes.Statistics.en.html
secondes.Statistiques.fr.html

file.xsl
================================================== ==============================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:variable name="LANGS" select="//span[not(@xml:lang=preceding::span/@xml:lan
g)]/@xml:lang"/>

<xsl:template match="@*|node()">
<xsl:for-each select="$LANGS">
<xsl:variable name="langs" select="."/>

<xsl:value-of select="$filename"/>.<xsl:value-of select='document("menu.xml")/me
nu/item[@name=$filename]/ch[titre=$chapitre]/titre[@lang=$langs]'/>.<xsl:value-o
f select="."/>.html

</xsl:for-each>
<xsl:text>&#xa;</xsl:text>
</xsl:template>
</xsl:stylesheet>
================================================== ==============================

file.xml
================================================== ==============================
<?xml version="1.0" encoding="ISO-8859-1"?>
<body>
<h1>
<span xml:lang="en">Level two</span>
<span xml:lang="fr">Secondes</span>
</h1>
</body>
================================================== ==============================

menu.xml
================================================== ==============================
<?xml version="1.0" encoding="ISO-8859-1"?>
<menu>
<item name='secondes'>
<ch>
<titre lang='en'>Statistics</titre>
<titre lang='fr'>Statistiques</titre>
</ch>
</item>
</menu>
================================================== ==============================

Is it the only solution ?

Regards
--
ph
Mar 25 '06 #5
Interesting. No, I really don't have an explanation for that behavior,
even after checking the specifications.

(If someone finds one, I'll be interested to know what I missed. If
nobody finds one... Try it in another XSLT processor; it might actually
turn out to be a bug.)
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 25 '06 #6
Le 25 Mar 2006 02:37:22 GMT,
Dans le forum comp.text.xml,
MONROUX philippe a écrit :
But your real question is why
<xsl:value-of
select='document("menu.xml")/menu/item[@name=$filename]/
ch[titre=$chapitre]/titre[@lang=$LANGS]'/>
is generating the same result every time.

The answer's simple: The expression is completely independent of the
values you're iterating over, so it *must* produce the same result
every time. The string value of a nodeset is the string value of the
first node in the nodeset, so you are always testing the first entry
in $LANG.

Changing it to [@lang=.] should help.


[@lang=.] don't work. The result is :

secondes..en.html
secondes..fr.html

One solution is to declare a new variable which name is for example
langs just after <xsl:for-each select="$LANGS"> to get the "current
value" of LANGS (like in files below). I don't like this solution but
it works fine. With the following command :

xsltproc -stringparam filename secondes -stringparam chapitre
Statistiques file.xsl file.xml

The results are :

secondes.Statistics.en.html
secondes.Statistiques.fr.html


finaly it's the way. There is one possibility : play with `""',
`''',`&quot;';`&apos;' but it's heavy (not realy a game isn'it)

bye
--
Philippe Monroux
Reunion island
55.3W -21.5S
Mar 29 '06 #7

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

Similar topics

7
by: Leif B. Kristensen | last post by:
I'm working with a Python program to insert / update textual data into a PostgreSQL database. The text has single and double quotes in it, and I wonder: What is the easiest way to escape quotes in...
3
by: Paul | last post by:
I have an Access 2000 database with a form that is giving me some major headaches. When you open the form, it displays all records and allows editing, but has AllowAdditions set to False so that...
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
18
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
4
by: Guadala Harry | last post by:
I need to place the following into a string... How can I properly escape the % " / < and > characters? <table width="100%" border="0" cellspacing="0" cellpadding="4px" class="hfAll"></Table> ...
3
by: Guadala Harry | last post by:
I'd like to know the answer to the following question so I can know what to expect with regard to other similar uses of escape characters and strings. While everything works fine - I'd like to know...
16
by: sudhir | last post by:
hi how to check escape key is pressed when accepting the string as input. Because I do not want to receive a string if user presses the ESCAPE key.. I used ascii code for comparision but I...
15
by: pkaeowic | last post by:
I am having a problem with the "escape" character \e. This code is in my Windows form KeyPress event. The compiler gives me "unrecognized escape sequence" even though this is documented in MSDN....
131
by: Lawrence D'Oliveiro | last post by:
The "escape" function in the "cgi" module escapes characters with special meanings in HTML. The ones that need escaping are '<', '&' and '"'. However, cgi.escape only escapes the quote character if...
5
by: vlsidesign | last post by:
The printf function returns "warning: unknown escape sequence: \040" for a backslash-space combination. If the ascii decimal number for space is 32 and the backslash is 92, why this particular...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.