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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saritha2008
    New Member
    • Sep 2008
    • 9

    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="srini vas.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">sra chakonda@novell .com</assinged_to>
    <reporter name="Aaron Burgemeister">a aron@novell.com </reporter>
    </bug>
    </bugzilla>

    So, i have written an XSLT as given below:

    <xsl:styleshe et 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="reporte r" />
    </reporter>
    <assigned_to>
    <xsl:apply-templates select="assigne e"/>
    </assigned_to>
    </bug>
    </xsl:for-each>
    </bugzilla>

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

    <xsl:template match="assignee ">
    <xsl:attribut e name="name">
    <xsl:value-of select="."/>
    </xsl:attribute>
    <xsl:when test=". = 'Aaron Burgemeister'"> aaron@novell.co m</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
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    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.
    [CODE=xml]<?xml version="1.0" encoding="utf-8" ?>
    <users>
    <mail name="Aaron Burgemeister">a aron@novell.com </mail>
    </users>[/CODE]

    regards

    Comment

    • saritha2008
      New Member
      • Sep 2008
      • 9

      #3
      HI,

      Thanks. Its working perfectly with document( ).

      Below is my XSLT:

      <xsl:styleshe et 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="sun itha.akula@appl abs.com" exporter="sunit ha.akula@applab s.com">
      <bug>
      <reporter>
      <xsl:apply-templates select="reporte r" />
      </reporter>
      <assigned_to>
      <xsl:apply-templates select="assigne e"/>
      </assigned_to>
      </bug>
      </bugzilla>
      </xsl:template>

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

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

      <xsl:template name="UserDetai ls">
      <xsl:param name="Value"/>
      <xsl:variable name="example" select="documen t('UserDetails. xml')/rss"/>
      <xsl:for-each select="$exampl e/User[FullName=$Value]">
      <xsl:value-of select="MailAdd ress"/>
      </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>ab c@novell.com</MailAddress>
      </User>
      <User>
      <FullName>X Y</FullName>
      <MailAddress>xy @novell.com</MailAddress>
      </User>
      </rss>

      Comment

      Working...