473,730 Members | 3,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT beginner's question

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 XML file format which has one header node and
several child nodes :

<wi workitemid= "99999" .... etc .... />
<widata dataname="AMOUN T" datadisplay="Am ount" datavalue="123. 45"/>
<widata dataname="ADDRE SS1" datadisplay="Ad dress" datavalue="Line
1" >
<widata .... etc ....

and am processing them using XSLT to produce an HTML table, by for
example :

<xsl:apply-templates select="widata[@dataname = 'AGENTNAME']"
mode="left_left "/>

The template puts the value of datadisplay into one table cell, and
the value of datavalue into the next cell.

So far, so good. However, how would I get the values from two widata
nodes and concatenate them so that I can put them into one cell? I
know about the concat function but I am having problems getting hold
of the values from the nodes and storing them so that I can then use
that function.

I hope I have included enough info to be helpful.

Thank-you.

Martin
Jul 20 '05 #1
13 18659
Use variables to hold the values and then concat the variables.

<td>

<xsl:variable name="state">
<xsl:value-of select="widata[@dataname = 'ADDRESS3']/@datavalue" />
<!-- or some other node selection -->
</xsl:variable>

<xsl:variable name="zip">
<xsl:value-of select="widata[@dataname = 'ADDRESS4']/@datavalue" />
<!-- or some other node selection -->
</xsl:variable>

....

<xsl:value-of select="concat( $state, ' ', $zip)" />

....

</td>

HTH,
-vin

Martin wrote:
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 XML file format which has one header node and
several child nodes :

<wi workitemid= "99999" .... etc .... />
<widata dataname="AMOUN T" datadisplay="Am ount" datavalue="123. 45"/>
<widata dataname="ADDRE SS1" datadisplay="Ad dress" datavalue="Line
1" >
<widata .... etc ....

and am processing them using XSLT to produce an HTML table, by for
example :

<xsl:apply-templates select="widata[@dataname = 'AGENTNAME']"
mode="left_left "/>

The template puts the value of datadisplay into one table cell, and
the value of datavalue into the next cell.

So far, so good. However, how would I get the values from two widata
nodes and concatenate them so that I can put them into one cell? I
know about the concat function but I am having problems getting hold
of the values from the nodes and storing them so that I can then use
that function.

I hope I have included enough info to be helpful.

Thank-you.

Martin


Jul 20 '05 #2
On 5 Sep 2003 10:00:57 -0700, co*****@hotmail .com (Martin) wrote:
However, how would I get the values from two widata
nodes and concatenate them so that I can put them into one cell?
With concat(), or by using two <xsl:value-of /> elements next to each
other.
I am having problems getting hold
of the values from the nodes and storing them so that I can then use
that function.


So don't store them. Write two XPath expressions, get them working
and tested separately, then cut-and-paste each one into the arguments
to concat()

Jul 20 '05 #3
Thank you both for your responses. They both make sense to me but I'm
still doing something not quite right because I can't get either of
them to transform.

Firstly my XPath expressions are fine now, thanks for the pointers.
I've put them in a couple of xsl:comments and the values are what I'm
after. However,

Vin - if I use your suggestion, I get the error

A reference to variable or parameter 'x' cannot be resolved. The
variable or parameter may not be defined, or it may not be in scope.

This has completely puzzled me as the only time at the moment I
reference the variable is when I try to allocate a value to it; I
haven't got to the point of trying to then use that value later on, so
how can it possibly be that when I create the variable and at the same
time allocate a value to it the variable is out of scope ?!

Andy - I have tried pasting my XPath expressions as you suggested :

<xsl:call-template name="left_left ">
<xsl:with-param name="data" select="concat(
xsl:value-of select='widata[@dataname =
&quot;AGENTID&q uot;]/@datavalue' ,
' ' ,
xsl:value-of select='widata[@dataname =
&quot;AGENTNAME &quot;]/@datavalue')"
/>
</xsl:call-template>

I get the error

Keyword xsl:call-template may not contain PCDATA nodes.

Please could you help me understand these issues.

Thanks,

Martin
Jul 20 '05 #4
In article <ac************ **************@ posting.google. com>,
Martin <co*****@hotmai l.com> wrote:

% <xsl:call-template name="left_left ">
% <xsl:with-param name="data" select="concat(
% xsl:value-of select='widata[@dataname =
% &quot;AGENTID&q uot;]/@datavalue' ,
% ' ' ,
% xsl:value-of select='widata[@dataname =
% &quot;AGENTNAME &quot;]/@datavalue')"
% />

You're trying to put xslt elements inside an xpath expression. Try

% <xsl:call-template name="left_left ">
% <xsl:with-param name="data" select="concat(
widata[@dataname ='AGENTID']/@datavalue,
% ' ' ,
widata[@dataname = 'AGENTNAME']/@datavalue)"
% />
% </xsl:call-template>

The suggestion to concatenate two xsl:value-of was simply to do that:

<xsl:template name="left_left ">
<!-- whatever -->
<xsl:value-of select ="widata[@dataname ='AGENTID']/@datavalue"/>
<xsl:value-of select ="widata[@dataname = 'AGENTNAME']/@datavalue"/>
<!-- whatever else -->
</xsl:template>
--

Patrick TJ McPhee
East York Canada
pt**@interlog.c om
Jul 20 '05 #5
pt**@interlog.c om (Patrick TJ McPhee) wrote in message news:<bj******* ***@news.eusc.i nter.net>...
You're trying to put xslt elements inside an xpath expression. Try

% <xsl:call-template name="left_left ">
% <xsl:with-param name="data" select="concat(
widata[@dataname ='AGENTID']/@datavalue,
% ' ' ,
widata[@dataname = 'AGENTNAME']/@datavalue)"
% />
% </xsl:call-template>


Thank you, Patrick. Yes, I was trying to make it more complicated
than was necessary. I have now got it working and I appreciate the
help that you and everyone else gave me.

I would still like to understand the problem I had earlier when trying
to use a variable. I have stripped down my stlyesheet to the
following minimum skeleton :

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body>
<xsl:variable name="agentname " select="0"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I still get the error : "A reference to variable or parameter
'agentname' cannot be resolved. The variable or parameter may not be
defined, or it may not be in scope".

Can anyone enlighten me as to what I am doing wrong here, please?

Martin
Jul 20 '05 #6
In article <ac************ *************@p osting.google.c om>,
Martin <co*****@hotmai l.com> wrote:

% to use a variable. I have stripped down my stlyesheet to the
% following minimum skeleton :
%
% <xsl:styleshe et version="1.0"
% xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
% xmlns:fo="http://www.w3.org/1999/XSL/Format">
%
% <xsl:output method="html"/>
% <xsl:template match="/">
% <html>
% <body>
% <xsl:variable name="agentname " select="0"/>
% </body>
% </html>
% </xsl:template>
% </xsl:stylesheet>

% I still get the error : "A reference to variable or parameter
% 'agentname' cannot be resolved. The variable or parameter may not be
% defined, or it may not be in scope".

Are you sure this is the stylesheet giving that error? There is no
reference to agentname here. Is there another stylesheet with
$agentname in it somewhere?

--

Patrick TJ McPhee
East York Canada
pt**@interlog.c om
Jul 20 '05 #7
Martin wrote:

I would still like to understand the problem I had earlier when trying
to use a variable. I have stripped down my stlyesheet to the
following minimum skeleton :

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body>
<xsl:variable name="agentname " select="0"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I still get the error : "A reference to variable or parameter
'agentname' cannot be resolved. The variable or parameter may not be
defined, or it may not be in scope".

Can anyone enlighten me as to what I am doing wrong here, please?


Are you using *-PARAM agentname* as a command-line option?

Jul 20 '05 #8
vin sharma <vi********@hp. com> wrote in message news:<1Q******* **********@news .cpqcorp.net>.. .
Are you using *-PARAM agentname* as a command-line option?


No, I am using XSLDebugger (http://www.vbxml.com/xsldebugger/)to do my
development, and it is this that is giving me the error message.

Should my previously posted stylesheet work OK? If so, then maybe
this product is buggy?? Is there another freeware product or
alternative method I can use instead?

Can I throw in another issue that I've come up against? Now that my
concat statement is working I want to add line breaks between my
values and so I am trying to get <BR> tags in my output HTML.

<xsl:call-template name="left_left ">
<xsl:with-param name="data" select="concat(
widata[@dataname = 'ADDRESS1']/@datavalue, '&#x3c;' 'BR',
'&#x3e;',
widata[@dataname = 'ADDRESS2']/@datavalue, '&#x3c;' 'BR',
'&#x3e;',
etc.

However, this gets transformed into
&lt;BR&gt;
not
<BR>
and so my HTML doesn't display as I want it.

How can I get the angle brackets to output please?

Martin
Jul 20 '05 #9
You can't output tags as data. Output them as HTML tags.

Bob Foster

"Martin" <co*****@hotmai l.com> wrote in message
news:ac******** *************** ***@posting.goo gle.com...
vin sharma <vi********@hp. com> wrote in message news:<1Q******* **********@news .cpqcorp.net>.. .
Are you using *-PARAM agentname* as a command-line option?


No, I am using XSLDebugger (http://www.vbxml.com/xsldebugger/)to do my
development, and it is this that is giving me the error message.

Should my previously posted stylesheet work OK? If so, then maybe
this product is buggy?? Is there another freeware product or
alternative method I can use instead?

Can I throw in another issue that I've come up against? Now that my
concat statement is working I want to add line breaks between my
values and so I am trying to get <BR> tags in my output HTML.

<xsl:call-template name="left_left ">
<xsl:with-param name="data" select="concat(
widata[@dataname = 'ADDRESS1']/@datavalue, '&#x3c;' 'BR',
'&#x3e;',
widata[@dataname = 'ADDRESS2']/@datavalue, '&#x3c;' 'BR',
'&#x3e;',
etc.

However, this gets transformed into
&lt;BR&gt;
not
<BR>
and so my HTML doesn't display as I want it.

How can I get the angle brackets to output please?

Martin

Jul 20 '05 #10

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

Similar topics

3
2124
by: Phil | last post by:
Hi everybody, I am a XSLT beginner and the following problem really makes me crazy ! I have a main "contacts.xml" document which contains references to several contact data XML files. My aim is to process the contacts in a single-pass XSLT process. That is why the "document()" function is what I need. I call the "document()" XPath function from a "for-each" instruction.
4
1417
by: timothy ma and constance lee | last post by:
do you know any good xslt book
3
1070
by: Martin Plantec | last post by:
This is a very simple question, from a beginner in XSLT. Suppose my XML says <para>The word <a href="there.html">link</a> goes there.</para> What XSLT rule would preserve the a element with all attributes? By now I have learned I can write:
3
1274
by: Chris | last post by:
Hi, I have an XML-file : <book> <title>Alaska</title> </book> I would like transfer the <book>-elements to <bookname> using an xsl-sheet, thus producing xml-again. and saving the output in a new xml-file
0
1931
by: inetquestion | last post by:
Can someone point me in the right direction regarding xml/xslt? I have the following xml file with corresponding xslt and would like to add some aditional functionality where a viewer can select from a dropdown menu or radio box which tier of servers to view thereby filtering out the others. From a few sources I've seen it looks like I would need to use xsl:with-param, but references I've seen of this do not explain it at my level...
5
1430
by: hilz | last post by:
Hi all I have this situation where I have an xml file similar to this: <Root> <MyElement year="2004"><Amount>10</Amount></MyElement> <MyElement year="2004"><Amount>11</Amount></MyElement> <MyElement year="2005"><Amount>15</Amount></MyElement> <MyElement year="2006"><Amount>4</Amount></MyElement> <MyElement year="2006"><Amount>7</Amount></MyElement> <MyElement year="2004"><Amount>20</Amount></MyElement>
4
1519
by: Adrian von Bidder | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Yo! Mostly as a finger-exercise (and because I'm annoyed again and again how bad the existing solutions are), I'm hacking up a web-based forum (yes, the 64832th one, I know). I want to allow some simplified HTML as input language, and use some xsl
18
2084
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to look up what each feature depends on and gerenate a text file. For example, in the following file, I would like to find out feature A depends on A1 and A2 and feature B depends on B1 and B2. And write that to a text file.
7
1962
by: pstachy | last post by:
Hi all, I'm having problem with XSLT transformation concerned with sort and numberings at a time. I wish to have my registries sorted alfabetically and would like them to have numberings at a time as well. My XML: <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="xsl.xsl"?>
0
9442
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...
0
9301
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9229
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
8184
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...
1
6725
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6030
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();...
1
3257
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
2
2713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.