Subject: Re: sorting and multiple output documents in xslt 2.0
From: Meghan Finch <meghan.finch@xxxxxxxxx>
Date: Fri, 29 Jul 2011 14:37:27 -0400
|
Hello Michael (and others),
I'm sorry for not better explaining. The xml element does exist,
though I did not include it in the example I provided. That is the
first element that houses all other elements. While it may not be the
best choice for an element, I am working with xml that is created by
another company, so I cannot control how they have designed their
schema. I am only trying to transform it to work with my local system.
There are several DISS_submission'ss all contained in one file, housed
within the element called xml. I am trying to sort each of those
DISS_submission's into two different output documents, depending on
whether their DISS_description@type attribute is either "masters" or
"doctoral." So while the example I provided has a type of "doctoral,"
there are other DISS_submission/DISS_description elements that have a
type attribute of "masters."
I hope that provided better clarification. So I am looking to sort
each DISS_submission with all child elements into 2 outputs depending
on what the DISS_description@type attribute value is, with several
DISS_submission 's all contained within one document.
Thanks again.
--Meghan
On Fri, Jul 29, 2011 at 2:18 PM, Michael Kay <mike@xxxxxxxxxxxx> wrote:
> On 29/07/2011 18:43, 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:
>
> Your template rule says
>
> <xsl:template match="xml">
>
> but I don't see an element named "xml". (It would be a poor choice of
> element name anyway, but that's by the by.
>
> I would also point out that this:
>
> <xsl:if test="DISS_submission/DISS_description[@type='masters']">
> <xsl:copy-of
> select="DISS_submission/DISS_description[@type='masters']"/>
> </xsl:if>
>
> is equivalent to this:
>
> <xsl:copy-of
> select="DISS_submission/DISS_description[@type='masters']"/>
>
> since if there's nothing to copy, then nothing gets copied.
>
>
> Beyond that, I'm just confused. Is there more than one DISS_submission
> element perhaps? Are you trying to produce one result document for several
> DISS_submission elements, or one for each?
>
> Michael Kay
> Saxonica
>
>> <?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
|