[xsl] Combining xml file manipulation into one xsl

Subject: [xsl] Combining xml file manipulation into one xsl
From: "Karen Dunstall" <kdunstall@xxxxxxxxxxxxxxx>
Date: Thu, 2 Oct 2003 09:04:13 +1000
Hi

I want to combine the workings of two xsl files into one.  I don't think this should be hard, but I seem to be having a total no-brain day.  Can anyone help me?

I take one xml file (index.xml), convert it to a format I want, then combine it with another, existing file (tblMasterFile.xml) of the same format and weed out the duplicates.  I can do each of these individually, but right now have to save the xml files in between.  That is:

I start with Convert.xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml" omit-xml-declaration="yes"/>
  <xsl:template match="/">
     <CodeLibrary>
    <xsl:for-each select="doxygenindex/compound">
      <File>
      <xsl:apply-templates select="."/>
      </File>
    </xsl:for-each>
    </CodeLibrary>
  </xsl:template>
  <xsl:template match="doxygenindex/compound">
    <Name><xsl:value-of select="name"/></Name>
    <Type><xsl:value-of select="@kind"/></Type>
    <BriefDescription/>
    <SourceFileName><xsl:value-of select="@refid"/></SourceFileName>
    <IgnoreFlag>77</IgnoreFlag>  
  </xsl:template>
</xsl:stylesheet>

And I save the result as a new xml file - newIndex.xml

Then I do a second transformation in a second xsl file (Merge.xsl) using the newly created xml file (newIndex.xml), plus another xml file (tblMasterFile) to combine these two files, eliminating any duplicates.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
    <CodeLibrary>
      <xsl:for-each select="document('tblMasterFile.xml')/CodeLibrary/File | document('newIndex.xml')/CodeLibrary/File[not(Name=document('tblMasterFile.xml')/CodeLibrary/File/Name)]">
        <xsl:sort select="Name"/>
        <File>
          <Name>
            <xsl:value-of select="./Name"/>
          </Name>
          <Type><xsl:value-of select="./Type"/></Type>
          <BriefDescription><xsl:value-of select="./BriefDescription"/></BriefDescription>
          <SourceFileName><xsl:value-of select="./SourceFileName"/></SourceFileName>
          <IgnoreFlag><xsl:value-of select="./IgnoreFlag"/></IgnoreFlag>
        </File>
      </xsl:for-each>
    </CodeLibrary>
  </xsl:template>
</xsl:stylesheet>


My xml is as follows:

Index.xml  -- a huge file, most of which I ignore for this exercise.

<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<doxygenindex>
  <compound refid="classCMembers" kind="class">
    <name>CMembers</name>
    <member refid="classCMembers" kind="function">
      <name>WriteXML</name>
    </member>
    <member refid="classCMembers" kind="function">
      <name>WriteValidXMLList</name>
    </member>
    <member refid="classCMembers" kind="function">
      <name>Retrieve</name>
    </member>
    <member refid="classCMembers" kind="function">
      <name>UpdateStatus</name>
    </member>
    <member refid="classCMembers" kind="function">
      <name>AddressChange</name>
    </member>
  </compound>
  <compound refid="cShares_8cpp" kind="file">
    <name>cShares.cpp</name>
    <member refid="cShares_8cpp" kind="function">
      <name>GetServiceAccountName</name>
    </member>
    <member refid="cShares_8cpp" kind="function">
      <name>GetSharesAccountNumber</name>
    </member>
    <member refid="cShares_8cpp" kind="function">
      <name>processSharePurchasePlan</name>
    </member>
    <member refid="cShares_8cpp" kind="function">
      <name>processNonRenouncableRightsIssue</name>
    </member>
  </compound>
</doxygenindex>


newIndex.xml and tblMasterFile.xml, both of which are the same format.

<CodeLibrary>
  <File>
    <Name>CMembers</Name>
    <Type>class</Type>
    <BriefDescription></BriefDescription>
    <SourceFileName>classCMembers</SourceFileName>
    <IgnoreFlag>77</IgnoreFlag>
  </File>
  <File>
    <Name>cShares.cpp</Name>
    <Type>file</Type>
    <BriefDescription>Define the classes for share manipulation.</BriefDescription>
    <SourceFileName>cShares_8cpp</SourceFileName>
    <IgnoreFlag>0</IgnoreFlag>
  </File>
</CodeLibrary>

Thanks
Karen

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread