473,385 Members | 1,356 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,385 software developers and data experts.

Can the XSLT read from an external excel file or some other flat file?

Hi,

As part of transforming one form of xml to another form, i need to do the below mentioned transformation:

My Input XML:

<rss>
<channel>
<item>
<assignee username="srinivas.rachakonda">Srinivas Rachakonda</assignee>
<reporter username="aaron.burgemeister">Aaron Burgemeister</reporter>
</item>
</channel>
</rss>

My Output should be:

<bugzilla>
<bug>
<assigned_to name="Srinivas Rachakonda">srachakonda@novell.com</assinged_to>
<reporter name="Aaron Burgemeister">aaron@novell.com</reporter>
</bug>
</bugzilla>

So, i have written an XSLT as given below:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<bugzilla>
<xsl:for-each select="/rss/channel/item">
<bug>
<reporter>
<xsl:apply-templates select="reporter" />
</reporter>
<assigned_to>
<xsl:apply-templates select="assignee"/>
</assigned_to>
</bug>
</xsl:for-each>
</bugzilla>

<xsl:template match="reporter">
<xsl:attribute name="name">
<xsl:value-of select="."/>
</xsl:attribute>
<xsl:when test=". = 'Aaron Burgemeister'">aaron@novell.com</xsl:when>
</xsl:choose>
</xsl:template>

<xsl:template match="assignee">
<xsl:attribute name="name">
<xsl:value-of select="."/>
</xsl:attribute>
<xsl:when test=". = 'Aaron Burgemeister'">aaron@novell.com</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:template>

</xsl:stylesheet>

The above XSLT is working fine.

1) But instead of hardcoding the mail address in XSLT, can i get them from an external file?
2) There are almost 25 to 30 users which i need to map. So, it may be good if we have an external file with the list of user names & their mail addresses. From the XSLT, i need to get each user name & compare it with the current node value. Wherever the match is occured, mail address of that user i need to get from that external file.
My question is, can an XSLT read from an external file like excel sheet or any other file?

Any help in this regard would be appreciated.

Thanks,
Saritha
Sep 26 '08 #1
2 9118
Dormilich
8,658 Expert Mod 8TB
you can use the xsl document() function. this will read a node-set of an external xml file. (though I've not yet used it)

you could write the user - email list in an xml too. e.g.
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <users>
  3.   <mail name="Aaron Burgemeister">aaron@novell.com</mail>
  4. </users>
regards
Sep 29 '08 #2
HI,

Thanks. Its working perfectly with document( ).

Below is my XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<bugzilla version="3.0.4" urlbase="http://172.16.6.51/proj11/" maintainer="sunitha.akula@applabs.com" exporter="sunitha.akula@applabs.com">
<bug>
<reporter>
<xsl:apply-templates select="reporter" />
</reporter>
<assigned_to>
<xsl:apply-templates select="assignee"/>
</assigned_to>
</bug>
</bugzilla>
</xsl:template>

<xsl:template match="reporter">
<xsl:attribute name="name">
<xsl:value-of select="."/>
</xsl:attribute>
<xsl:call-template name="UserDetails">
<xsl:with-param name="Value" select="."/>
</xsl:call-template>
</xsl:template>

<xsl:template match="assignee">
<xsl:attribute name="name">
<xsl:value-of select="."/>
</xsl:attribute>
<xsl:call-template name="UserDetails">
<xsl:with-param name="Value" select="."/>
</xsl:call-template>
</xsl:template>

<xsl:template name="UserDetails">
<xsl:param name="Value"/>
<xsl:variable name="example" select="document('UserDetails.xml')/rss"/>
<xsl:for-each select="$example/User[FullName=$Value]">
<xsl:value-of select="MailAddress"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

UserDetails.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="0.92">
<User>
<FullName>ABC</FullName>
<MailAddress>abc@novell.com</MailAddress>
</User>
<User>
<FullName>X Y</FullName>
<MailAddress>xy@novell.com</MailAddress>
</User>
</rss>
Sep 30 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: shaun | last post by:
Question about :what is a reasonable time for a transform? I am transforming an XML file of ~70 000 lines into a file of ~100 000 lines using XSLT, and also doing the reverse to reconstitute the...
2
by: sam | last post by:
Hi, I've been buried in xsl and xslt articles for several days now, and am still unsure as to what I need to do... Basically, my vb.net app loads up an XML file from an external source...
2
by: solex | last post by:
Hello, Is there a way to develop a style sheet that runs on the client that will open the file in excel? Thanks, Dan
4
by: dar_imiro | last post by:
Hi, I'm trying to get rid of frames as menu holder in my html-page. I'd also like to separate the menu structure to xml and xslt. Also the actual content is divided to xml and its corresponding...
3
by: R. P. | last post by:
Subject: XSLT to transform a flat XML file into a structured text file I have an XML file that lists the PDF file segment names and titles of a larger document and looks something like this: ...
1
by: pyrotechnique | last post by:
What I'm doing is that I have some automation pieces set up that take a flat .txt file, applies an xsd to this to turn it into a flat XML file, and I then apply an XSLT to this flat XML file to turn...
2
by: murthydb2 | last post by:
Hi My requirement is that i have to write a stored procedure in db2 and that will be executed in a batch file . Any system error or validation error that occurs inside the db2 sp during...
0
by: Tony Hine | last post by:
Problem for Excel Developers One of the problems facing Excel developers moving into MS Access is actually the apparent similarity between MS Access tables and Excel spreadsheets. MS Access is...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.