473,398 Members | 2,165 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,398 software developers and data experts.

XSLT: using variables

Hi,

In the variable "anchor" I would like to,
(I think), use the value of the variable "text"
in the predicate of the select expression.
Is this possible?

Is there a better way of doing
what I think I want to do?

Is there an easier way of using the values
of variables other than thru the value-of element?

<xsl:template match="addinfo">

<xsl:variable name="text"
select="addinfo_link_text"/>

<xsl:variable name="prefix"
select="addinfo_prefix"/>

<xsl:variable name="anchor"
select="//section/anchor
[../section_header = '$text']"/>

<xsl:variable name="page"
select="addinfo_pg_no"></xsl:variable>

<xsl:variable name="postfix"
select="addinfo_postfix"/>

<span><a>
<xsl:attribute name="href"><xsl:value-of
select="$anchor"/></xsl:attribute>
<xsl:value-of select="$prefix"/>
<xsl:value-of select="$text"/>
<xsl:value-of select="$postfix"/>
<xsl:value-of select="$page"/>
</a></span>

<xsl:apply-templates/>
</xsl:template>

Thanks
Jeff Higgins
May 14 '06 #1
8 1641
Jeff Higgins wrote:
<xsl:variable name="anchor"
select="//section/anchor[../section_header = '$text']"/>


Entirely reasonable; should work...
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
May 14 '06 #2
In article <wZ******************************@comcast.com>,
Joe Kesselman <ke************@comcast.net> wrote:
Jeff Higgins wrote:
<xsl:variable name="anchor"
select="//section/anchor[../section_header = '$text']"/>
Entirely reasonable; should work...


So long as what you want is section_headers equal to '$text' rather
than the value of the variable $text...

-- Richard
May 14 '06 #3

Joe Kesselman wrote:
Entirely reasonable; should work...


really can't seem to make the right selection
for the anchor variable?

Other problems too. But I'll work on that.

Sorry for the bulky post.

Result:

<span><a href="">For further information, See "User Interface" on page
10.10</a></span>
<span><a href="">For further information, See "Menus" on page
20.20</a></span>
<span><a href="">For further information, See "Getting Started" on page
1.1</a></span>

Desired output:

<span><a href="2_UserInterface">For further information, See "User
Interface" on page 10.</a></span>
<span><a href="3_Menus">For further information, See "Menus" on page
20.</a></span>
<span><a href="1_GettingStarted">For further information, See "Getting
Started" on page 1.</a></span>

<xsl:template match="info">
<xsl:variable name="text" select="text"/>
<xsl:variable name="anchor" select="ancestor::anchor[../header =
'$text']"/>
<span>
<a>
<xsl:attribute name="href"><xsl:value-of
select="$anchor"/></xsl:attribute>
<xsl:value-of select="prefix"/>
<xsl:value-of select="text"/>
<xsl:value-of select="postfix"/>
<xsl:value-of select="postfix/page"/>
</a>
</span>
<xsl:apply-templates/>
</xsl:template>

<chapter>
<anchor>1_GettingStarted</anchor>
<header>Getting Started</header>
<info>
<prefix>For further information, See "</prefix>
<text>User Interface</text>
<postfix>" on page <page>10</page>.</postfix>
</info>
<section>
<anchor>2_UserInterface</anchor>
<header>User Interface</header>
<info>
<prefix>For further information, See "</prefix>
<text>Menus</text>
<postfix>" on page <page>20</page>.</postfix>
</info>
</section>
<section>
<anchor>3_Menus</anchor>
<header>Menus</header>
<info>
<prefix>For further information, See "</prefix>
<text>Menus</text>
<postfix>" on page <page>100</page>.</postfix>
</info>
</section>
</chapter>
May 14 '06 #4


Jeff Higgins wrote:

<xsl:variable name="text" select="text"/>
<xsl:variable name="anchor" select="ancestor::anchor[../header =
'$text']"/>


As Richard has already pointed out, you most likely want/need

<xsl:variable name="anchor" select="ancestor::anchor[../header =
$text]"/>

as otherwise (with '$text') you simply compare to the literal string
with '$text' and not to a variable value.
--

Martin Honnen
http://JavaScript.FAQTs.com/
May 14 '06 #5
Martin Honnen wrote:
as otherwise (with '$text') you simply compare to the literal string
with '$text' and not to a variable value.


Whups. I shoulda caught that. That's what I get for not testing before
posting. <grin/>

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
May 14 '06 #6

Martin Honnen wrote:


Jeff Higgins wrote:

<xsl:variable name="text" select="text"/>
<xsl:variable name="anchor" select="ancestor::anchor[../header =
'$text']"/>


As Richard has already pointed out, you most likely want/need

<xsl:variable name="anchor" select="ancestor::anchor[../header =
$text]"/>

as otherwise (with '$text') you simply compare to the literal string with
'$text' and not to a variable value.


Yes. Thanks, I did catch that, although you couldn't tell it from
my most recent (faulty) post.

Sorry for changing examples in mid-thread.

As it turns out, the following template does very nearly what I want:

<xsl:template match="addinfo">
<xsl:variable name="text" select="addinfo_link_text"/>
<xsl:variable name="anchor" select="ancestor::section[./section_header =
$text] | ancestor::chapter[./chapter_header = $text]"/>
<xsl:variable name="anchortext" select="$anchor/section/section_header |
$anchor/chapter/chapter_header"></xsl:variable>
<span>
<a>
<xsl:attribute name="href"><xsl:value-of
select="$anchortext"/></xsl:attribute>
<xsl:value-of select="addinfo_prefix"/>
<xsl:value-of select="addinfo_link_text"/>
<xsl:value-of select="addinfo_postfix"/>
<xsl:value-of select="addinfo_postfix/addinfo_pg_no"/>
</a>
</span>
<xsl:apply-templates/>
</xsl:template>
May 14 '06 #7
Correction:

<xsl:variable name="anchortext" select="$anchor/section/anchor |
$anchor/chapter/anchor"></xsl:variable>
May 14 '06 #8
Hi,

I made kind of a mess of this thread by
being in a hurry, but anyway, for the
sake of posterity the following produces
the desired result.

Thanks everybody.
Jeff Higgins
Desired and achieved result:
<span>For further information on this subject, see "<a
href="1_UserInterface">User Interface</a>" on page 10.</span>
<span>For further information on this subject, see "<a
href="1_1_1_Menus">Menus</a>" on page 20.</span>
<span>For further information on this subject, see "<a
href="1_GettingStarted">Getting Started</a>" on page 1.</span>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="/|@*|node()">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="addinfo">
<xsl:variable name="text" select="addinfo_link_text"/>
<xsl:variable name="anchor" select="//section[section_header = $text] |
//chapter[chapter_header = $text]"/>
<xsl:variable name="anchortext" select="$anchor/anchor |
$anchor/anchor"/>
<span>
<xsl:value-of select="addinfo_prefix"/>
<a>
<xsl:attribute name="href"><xsl:value-of
select="$anchortext"/></xsl:attribute>
<xsl:value-of select="addinfo_link_text"/>
</a>
<xsl:value-of select="addinfo_postfix/text()[1]"/>
<xsl:value-of select="addinfo_postfix/addinfo_pg_no"/>
<xsl:value-of select="addinfo_postfix/text()[2]"/>
</span>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>

<chapter>
<anchor>1_GettingStarted</anchor>
<chapter_header>Getting Started</chapter_header>
<paragraph>This section covers the fundamental</paragraph>
<paragraph>
<addinfo>
<addinfo_prefix>For further information on this subject, see
"</addinfo_prefix>
<addinfo_link_text>User Interface</addinfo_link_text>
<addinfo_postfix>" on page
<addinfo_pg_no>10</addinfo_pg_no>.</addinfo_postfix>
</addinfo>
</paragraph>
<section>
<anchor>1_UserInterface</anchor>
<section_header>User Interface</section_header>
<paragraph>This section provides information on</paragraph>
<paragraph>
<addinfo>
<addinfo_prefix>For further information on this subject, see
"</addinfo_prefix>
<addinfo_link_text>Menus</addinfo_link_text>
<addinfo_postfix>" on page
<addinfo_pg_no>20</addinfo_pg_no>.</addinfo_postfix>
</addinfo>
</paragraph>
<section>
<anchor>1_1_ComponentsoftheUI</anchor>
<section_header>Components of the UI</section_header>
<paragraph>The main area of the screen is </paragraph>
<paragraph>
<addinfo>
<addinfo_prefix>For further information on this subject, see
"</addinfo_prefix>
<addinfo_link_text>Getting Started</addinfo_link_text>
<addinfo_postfix>" on page
<addinfo_pg_no>1</addinfo_pg_no>.</addinfo_postfix>
</addinfo>
</paragraph>
<section>
<anchor>1_1_1_Menus</anchor>
<section_header>Menus</section_header>
<paragraph>The main menu contains</paragraph>
</section>
<section>
<anchor>1_1_2_Toolbars</anchor>
<section_header>Toolbars</section_header>
<paragraph>The toolbars are located</paragraph>
</section>
</section>
</section>
</chapter>
May 14 '06 #9

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

Similar topics

2
by: ted | last post by:
Was wondering if XSLT alone is appropriate for the following situation. From XML, I'm creating a small website (around 50 pages) with pages that link to each other through a nav menu and a...
13
by: Martin | last post by:
I have 5 days of experince with XSLT and I am sure my problem is pretty much as basic as they come but I cannot work it out, so I hope someone will take pity on me - please! I have inherited an...
2
by: philips | last post by:
Hi everybody, I am using the Xalan 1.8 C++ API in a real-time financial application which need to apply XSLT transformations on XML input messages received on-the- fly. On the process output,...
4
by: Frederik Sørensen | last post by:
I include a xslt stylesheet with variables for all the error messages in my system. <xsl:variable name="Banner_error_1"> errormessage 1 for banner </xsl:variable> <xsl:variable...
1
by: Oleg Konovalov | last post by:
Hi, I am new to XSLT, trying to significantly modify somebody else's XSL. That is not 2.0. I need to create min & max variable(s) to be used in many templates and sub-templates based on...
12
by: Keith Chadwick | last post by:
I have a fairly hefty XSLT file that for the sake of debugging and clarity I wish to split into some separate sub-templates contained within the same file. The master template calls an...
4
by: darrel | last post by:
I think I've gotten the hang of XML and XSLT...at least enough to produce the results I'm looking for. I now need to take the next step and use ASP.NET (using VB.NET) to take the xml and send it...
6
by: Mike Grass | last post by:
Hi, I have an XML file similar to the following: <!-- snippet --> <selector key='USER/id' value='type1'/> <selector key='USER/id' value='type2'/> <selector key='USER/id' value='type3'/>...
1
by: balderdash | last post by:
Hi I am very close to achieving the output I need but I cant seem to get it right. The problem is I am looping through a table and selecting values, if there are 2 values per (row) Issuer I...
2
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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...
0
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,...
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.