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

XSL Transform Control Display Name

My XML looks like:

<abc>
<def type="apple"> 1 </def>
<def type="peach"> 2 </def>
<def type="orange"> 3 </def>
<def type="banana"> 4 </def>
<def type="plum"> 5 </def>
</abc>

I can write the transform to have this display as

apple 1
peach 2
orange 3
banana 4
plum 5

However I want to create more flexibility in displaying the names. So
say I have an external text file something like:

apple Xapple
peach Xpeach
orange Xorange
banana Xbanana
plum Xplum

the first column is the internal names i.e. actual names as found in the
XML and the second column is user-defined (external names and hence
variant). So I want the XML to be displayed as

Xapple 1
Xpeach 2
Xorange 3
Xbanana 4
Xplum 5

i.e. I want to get the external name corresponding to the internal name
from the file and use that external name to display the value of the
element. This way a user can control the names used in the display by
merely editing the external text file and not having to work with
XML/XSLT. Any suggestions/pointers will be highly appreciated.

TIA.




Jul 20 '05 #1
2 2715
Ravi wrote:
My XML looks like:

<abc>
<def type="apple"> 1 </def>
<def type="peach"> 2 </def>
<def type="orange"> 3 </def>
<def type="banana"> 4 </def>
<def type="plum"> 5 </def>
</abc>

I can write the transform to have this display as

apple 1
peach 2
orange 3
banana 4
plum 5

However I want to create more flexibility in displaying the names. So
say I have an external text file something like:

apple Xapple
peach Xpeach
orange Xorange
banana Xbanana
plum Xplum

the first column is the internal names i.e. actual names as found in the
XML and the second column is user-defined (external names and hence
variant). So I want the XML to be displayed as

Xapple 1
Xpeach 2
Xorange 3
Xbanana 4
Xplum 5

i.e. I want to get the external name corresponding to the internal name
from the file and use that external name to display the value of the
element. This way a user can control the names used in the display by
merely editing the external text file and not having to work with
XML/XSLT. Any suggestions/pointers will be highly appreciated.


I thought of using Javascript (cannot read an external file so I
hardcoded the internal-external mappings into an associative array as
shown below.

<xsl:script language="javascript" implements-prefix="user">
<![CDATA[
function GetExternal(internal)
{
var my_cars= new Array()
my_cars["apple"]="Xapple";
my_cars["peach"]="Xpeach";
my_cars["orange"]="Xorange";
my_cars["banana"]="Xbanana";
my_cars["plum"]="Xplum";
return my_cars[internal];
}
]]>
</xsl:script>

and when I want to do the display I do

<xsl:template match="def">
<xsl:variable name="tmp"><xsl:value-of select="@type"/> </xsl:variable>
<xsl:value-of select="user:GetExternal($tmp)" />
<xsl:value-of select="."/>
</xsl:template>
but it does not work saying xsl:script cannot be declared in stylesheet
(or namespace?). Can someone kindly shed some light on how to use
javascript in xsl? Or can this kind of mapping be done at the XSL level
itself? Your comments are highly appreciated.

Thanks.
Jul 20 '05 #2
In article <bp**********@prometheus.acsu.buffalo.edu>,
Ravi <rg**@cse.buffalo.edu> wrote:

% However I want to create more flexibility in displaying the names. So
% say I have an external text file something like:
%
% apple Xapple
% peach Xpeach
% orange Xorange
% banana Xbanana
% plum Xplum

You can encode the external file in xml and access it using document()
in an XPath expression.

fruit.xml:

<fruit>
<name type='apple'>Xapple</name>
<name type='peach'>Xpeach</name>
<name type='orange'>Xorange</name>
<name type='banana'>Xbanana</name>
<name type='plum'>Xplum</name>
</fruit>

Then instead of
<xsl:template match='def'>
<xsl:value-of select='@type'/>
...
<xsl:template match='def'>

you could write

<xsl:template match='def'>
<xsl:variable name='type' select='@type'/>
<xsl:value-of select='document("fruit.xml")/fruit/name[@type=$type]'/>
...
<xsl:template match='def'>

You could have the list of names as part of your stylesheet if that's
more convenient

<mf:fruit>
<mf:name type='apple'>Xapple</mf:name>
<mf:name type='peach'>Xpeach</mf:name>
<mf:name type='orange'>Xorange</mf:name>
<mf:name type='banana'>Xbanana</mf:name>
<mf:name type='plum'>Xplum</mf:name>
</mf:fruit>

<xsl:template match='def'>
<xsl:variable name='type' select='@type'/>
<xsl:value-of select='document("")/mf:fruit/mf:name[@type=$type]'/>
...
<xsl:template match='def'>

--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #3

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

Similar topics

1
by: Barry Anderberg | last post by:
I have an XML document that I am trying to display in my ASP.NET page. I am using an XSL Transform to display repeating XML data in a specific format. It reads the data, and displays it on my...
6
by: Gary Huntress | last post by:
Hi, I'm having trouble with an xslt transform. I'm trying to transform a vector into an array of width N. For example here is my vector: <data> <x id="1">1.2</x> <x id="2">.2</x> <x...
0
by: Sharon | last post by:
Hi y'all, I have a Delphi dll which generates XML from data in a db. I then use an XSL to transform and display the data in tabular form. Now what I want is a link saying 'export table', and make...
6
by: Stephen Cook | last post by:
Having worked through the problems around enabling the document function using an XmlUrlResolver I started work on building a useful class to hide the intricacies. Trying to generalise the process...
0
by: Edmund Rhudy | last post by:
Okay, this one's been bugging me for a few hours and I can't figure out what to do about it. I've been working on a little project for work that will take an RSS feed, extract certain items from...
2
by: suzy | last post by:
if i have an xsl transform that results in a table being generated, how do i display that table on my page at runtime? currently i am having to dim a table control with a row and a cell, then...
11
by: trinitypete | last post by:
Hi all, I have a user control that uses control literal to build a heading with a link, and a div containing links below. As the link heading is hit, I want to change the style of the div,...
3
by: vitaly.tomilov | last post by:
I'm using an ASP.NET form to display data from my database table, and I'm doing it in the following way: XmlDataDocument doc = new XmlDataDocument(mydataSet); XPathNavigator nav =...
7
by: Bilal | last post by:
Hello all, I came across this problem while working out the bugs in my identity trasnformation stylesheets but sidestepped it for later to see if there is an easier/better solution. This is...
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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.