Re: [xsl] sorting and multiple output documents in xslt 2.0

Subject: Re: [xsl] sorting and multiple output documents in xslt 2.0
From: Wolfhart Totschnig <wolfhart@xxxxxxxxxxxxx>
Date: Fri, 29 Jul 2011 13:52:14 -0500
Hi,

From what I can see, you need to replace

<xsl:copy-of select="DISS_submission/DISS_description[@type='masters']"/>

with

<xsl:copy-of select="DISS_submission[DISS_description/@type='masters']"/>


Wolfhart



Meghan Finch wrote:
Hello,

I am new to the listserv and was hoping that I could find some help. I
am working on a transformation that will take xml that describes
theses and dissertations and produce two different xml outputs, one
with all of the theses and the other with all of the dissertations.
This is an example of a single thesis/dissertation xml record:

<?xml version="1.0" encoding="UTF-8"?>
<DISS_submission publishing_option="0" embargo_code="0"
third_party_search="Y" third_party_sales="N">
   <DISS_authorship>
       <DISS_author type="primary">
           <DISS_name>
               <DISS_surname></DISS_surname>
               <DISS_fname></DISS_fname>
               <DISS_middle/>
               <DISS_suffix/>
               <DISS_affiliation></DISS_affiliation>
           </DISS_name>
           <DISS_contact type="current">
               <DISS_contact_effdt></DISS_contact_effdt>
               <DISS_address>
                   <DISS_addrline></DISS_addrline>
                   <DISS_addrline></DISS_addrline>
                   <DISS_city></DISS_city>
                   <DISS_st></DISS_st>
                   <DISS_pcode></DISS_pcode>
                   <DISS_country></DISS_country>
               </DISS_address>
               <DISS_email></DISS_email>
           </DISS_contact>
           <DISS_contact type="future">
               <DISS_contact_effdt></DISS_contact_effdt>
               <DISS_address>
                   <DISS_addrline></DISS_addrline>
                   <DISS_addrline></DISS_addrline>
                   <DISS_city></DISS_city>
                   <DISS_st></DISS_st>
                   <DISS_pcode></DISS_pcode>
                   <DISS_country></DISS_country>
               </DISS_address>
               <DISS_email></DISS_email>
           </DISS_contact>
           <DISS_citizenship></DISS_citizenship>
       </DISS_author>
   </DISS_authorship>
   <DISS_description page_count="115" type="doctoral"
external_id="http://id.pdf"; apply_for_copyright="no">
       <DISS_title></DISS_title>
       <DISS_dates>
           <DISS_comp_date></DISS_comp_date>
           <DISS_accept_date></DISS_accept_date>
       </DISS_dates>
       <DISS_degree></DISS_degree>
       <DISS_institution>
           <DISS_inst_code></DISS_inst_code>
           <DISS_inst_name></DISS_inst_name>
           <DISS_inst_contact></DISS_inst_contact>
           <DISS_processing_code></DISS_processing_code>
       </DISS_institution>
       <DISS_advisor>
           <DISS_name>
               <DISS_surname></DISS_surname>
               <DISS_fname></DISS_fname>
               <DISS_middle></DISS_middle>
           </DISS_name>
       </DISS_advisor>
       <DISS_cmte_member>
           <DISS_name>
               <DISS_surname></DISS_surname>
               <DISS_fname></DISS_fname>
               <DISS_middle/>
               <DISS_suffix/>
               <DISS_affiliation/>
           </DISS_name>
       </DISS_cmte_member>
       <DISS_cmte_member>
           <DISS_name>
               <DISS_surname></DISS_surname>
               <DISS_fname></DISS_fname>
               <DISS_middle/>
               <DISS_suffix/>
               <DISS_affiliation/>
           </DISS_name>
       </DISS_cmte_member>
       <DISS_cmte_member>
           <DISS_name>
               <DISS_surname></DISS_surname>
               <DISS_fname></DISS_fname>
               <DISS_middle/>
               <DISS_suffix/>
               <DISS_affiliation/>
           </DISS_name>
       </DISS_cmte_member>
       <DISS_categorization>
           <DISS_category>
               <DISS_cat_code></DISS_cat_code>
               <DISS_cat_desc></DISS_cat_desc>
           </DISS_category>
           <DISS_keyword/>
           <DISS_language></DISS_language>
       </DISS_categorization>
   </DISS_description>
   <DISS_content>
       <DISS_abstract>
           <DISS_para></DISS_para>
       </DISS_abstract>
       <DISS_binary type="PDF"></DISS_binary>
   </DISS_content>
   <DISS_restriction/>
</DISS_submission>

There are 3 elements inside DISS_submission that are important:
DISS_authorship, DISS_description, and DISS_content. Here is the xsl
that Ive been trying so far:

<xsl:stylesheet version="2.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   xmlns:xs="http://www.w3.org/2001/XMLSchema";>
   <xsl:output method="xml" indent="yes"/>

<xsl:template match="xml">
   <xsl:result-document href="masters.xml">

       <xsl:if test="DISS_submission/DISS_description[@type='masters']">
           <xsl:copy-of
select="DISS_submission/DISS_description[@type='masters']"/>
       </xsl:if>

   </xsl:result-document>
   <xsl:result-document href="doctoral.xml">

       <xsl:if test="DISS_submission/DISS_description[@type='doctoral']">
        <xsl:copy-of
select="DISS_submission/DISS_description[@type='doctoral']"/>
       </xsl:if>

   </xsl:result-document>
   </xsl:template></xsl:stylesheet>

This does actually create two outputs, one for masters and one for
theses. However, it only copies the DISS_description element and its
children. I want the entire DISS_submission to be copied. Ive tried
replacing xsl:copy-of to just DISS_submission but that just creates
two new documents with all of the DISS_submission s, not a sort
between masters and doctoral.

Im fairly new to xsl and not really a programmer, so forgive me
please for any obvious oversights here. XPATH also tends to give me a
lot of difficulty, so it could be something simple in there to fix.
I'm using Saxon to complete the transform. Thank you for the help and
feedback.

--Meghan Finch

Current Thread