Connecting Tech Pros Worldwide Help | Site Map

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

 
LinkBack Thread Tools Search this Thread
  #1  
Old September 26th, 2008, 05:36 AM
Newbie
 
Join Date: Sep 2008
Posts: 9
Default 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
Reply
  #2  
Old September 29th, 2008, 02:06 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Age: 32
Posts: 2,208
Default Can the XSLT read from an external excel file or some other flat file?

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
Reply
  #3  
Old September 30th, 2008, 10:36 AM
Newbie
 
Join Date: Sep 2008
Posts: 9
Default

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>
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.