By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,967 Members | 1,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,967 IT Pros & Developers. It's quick & easy.

escape problem ?

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
Impossible to answer without seeing what you're setting LANGS to and
what your input document is.
Mar 24 '06 #2

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.