Copy entire document after transform
Hi,
I'm attempting a simple (!) xsl transformation, taking an input xml document, adding elements, and outputting an exact copy with the added element data.
For this I apply a template to insert the required element data and perform an identity transformaion to copy all remaining information from the input xml.
However, the identity transformation is dropping some text from first level elements and I just can't find the 'magic formula' in the identity transformation to prevent this. Please help!!
Input xml:
<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE exercise SYSTEM "exercise.dtd">
<exercise bg-graphic="1" version="1" id="MEP005076" template="21">
<metadata>
<rf>
<level name="ELE"/>
<age range="AUT"/>
<english dialect="BRI"/>
<exam>KET</exam>
<content type="MEP"></content>
</rf>
</metadata>
<title>Paper 1 Part 5</title>
<subhead>Reading and Writing: gapped text</subhead>
<desc-grp>
<desc lang="EN">This exercise is suitable for KET. This Reading and Writing Part 5 exercise focuses mainly on grammar. You choose the correct words to complete a text about Pete Sampras.</desc>
</desc-grp>
<task id="005076TAS01" feedback="y">
<rubric-grp zonenum="1" sequence="1">
<rubric lang="EN">
<para>Click on the correct word in each drop-down menu to complete the text.</para>
</rubric>
</rubric-grp>
<activity zonenum="2" sequence="1">
<gapfill type="dropdown">
<gappara>
<emph type="bold">Pete Sampras</emph>
</gappara>
<gappara>Pete Sampras is one of <gap>
<answer true="y">A the</answer>
<answer true="n">B some</answer>
<answer true="n">C these</answer>
</gap> best tennis players in history. He began <gap>
<answer true="n">A play</answer>
<answer true="n">B played</answer>
<answer true="y">C playing</answer>
</gap> tennis when he <gap>
<answer true="n">A got</answer>
<answer true="n">B had</answer>
<answer true="y">C was</answer>
</gap> seven years old. He found an old tennis racquet in his house. His parents didn't have enough money to pay <gap>
<answer true="n">A on</answer>
<answer true="y">B for</answer>
<answer true="n">C with</answer>
</gap> tennis lessons <gap>
<answer true="y">A so</answer>
<answer true="n">B why</answer>
<answer true="n">C that</answer>
</gap> he practised by himself.</gappara>
<gappara>
<br/>
</gappara>
<gappara>Then the family moved to California. Here, they joined a tennis club and Pete played tennis a lot. <gap>
<answer true="n">A He</answer>
<answer true="n">B There</answer>
<answer true="y">C It</answer>
</gap> became clear that Pete was very good indeed and <gap>
<answer true="y">A in</answer>
<answer true="n">B then</answer>
<answer true="n">C before</answer>
</gap> a few years he was winning championships. Pete retired in 2003.</gappara>
<gappara>
<br/>
</gappara>
<gappara>Although Pete was a very competitive player, <gap>
<answer true="n">A his</answer>
<answer true="y">B he</answer>
<answer true="n">C him</answer>
</gap> is a very easy-going and kind person.</gappara>
</gapfill>
</activity>
</task>
<help>
<hint-grp>
<hint lang="EN">
<para>Read the article and the questions very carefully. Decide which answer you think is correct by thinking about the complete sentence, not just the word before each gap.</para>
</hint>
</hint-grp>
</help>
<decoration zonenum="3" sequence="1">
<graphic id="ill-xxx-004434-xxx-v001"/>
</decoration>
</exercise>
XSL:
All I'm doing is adding elements to the metadata tag and copying everything else across, the xsl is currently:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<!-- Standard matching to root element. -->
<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="metadata">
<metadata>
<xsl:apply-templates select="@* | *"/>
<flash_player version="1.0"/>
<example_text></example_text>
<time amount="5 mins"/>
</metadata>
</xsl:template>
<!-- This is the catch-all to process all other elements, i.e. outputting all other elements unchanged.-->
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Output XML:
The output is as follows. Please note the dropped 'exam', 'title' text, etc:
<?xml version="1.0" encoding="UTF-8"?>
<exercise bg-graphic="1" version="1" id="MEP005076" template="21">
<metadata xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<rf>
<level name="ELE"/>
<age range="AUT"/>
<english dialect="BRI"/>
<exam/>
<content type="MEP"/>
</rf>
<flash_player version="1.0"/>
<example_text/>
<time amount="5 mins"/>
</metadata>
<title/>
<subhead/>
<desc-grp>
<desc lang="EN">This exercise is suitable for KET. This Reading and Writing Part 5 exercise focuses mainly on grammar. You choose the correct words to complete a text about Pete Sampras.</desc>
</desc-grp>
<task id="005076TAS01" feedback="y">
<rubric-grp zonenum="1" sequence="1">
<rubric lang="EN">
<para/>
</rubric>
</rubric-grp>
<activity zonenum="2" sequence="1">
<gapfill type="dropdown">
<gappara>
<emph type="bold">Pete Sampras</emph>
</gappara>
<gappara>Pete Sampras is one of <gap>
<answer true="y">A the</answer>
<answer true="n">B some</answer>
<answer true="n">C these</answer>
</gap> best tennis players in history. He began <gap>
<answer true="n">A play</answer>
<answer true="n">B played</answer>
<answer true="y">C playing</answer>
</gap> tennis when he <gap>
<answer true="n">A got</answer>
<answer true="n">B had</answer>
<answer true="y">C was</answer>
</gap> seven years old. He found an old tennis racquet in his house. His parents didn't have enough money to pay <gap>
<answer true="n">A on</answer>
<answer true="y">B for</answer>
<answer true="n">C with</answer>
</gap> tennis lessons <gap>
<answer true="y">A so</answer>
<answer true="n">B why</answer>
<answer true="n">C that</answer>
</gap> he practised by himself.</gappara>
<gappara>
<br/>
</gappara>
<gappara>Then the family moved to California. Here, they joined a tennis club and Pete played tennis a lot. <gap>
<answer true="n">A He</answer>
<answer true="n">B There</answer>
<answer true="y">C It</answer>
</gap> became clear that Pete was very good indeed and <gap>
<answer true="y">A in</answer>
<answer true="n">B then</answer>
<answer true="n">C before</answer>
</gap> a few years he was winning championships. Pete retired in 2003.</gappara>
<gappara>
<br/>
</gappara>
<gappara>Although Pete was a very competitive player, <gap>
<answer true="n">A his</answer>
<answer true="y">B he</answer>
<answer true="n">C him</answer>
</gap> is a very easy-going and kind person.</gappara>
</gapfill>
</activity>
</task>
<help>
<hint-grp>
<hint lang="EN">
<para/>
</hint>
</hint-grp>
</help>
<decoration zonenum="3" sequence="1">
<graphic id="ill-xxx-004434-xxx-v001"/>
</decoration>
</exercise>
HELP!!:
Any help would be much appreciated, I've tried lots of various identity transformations all with the same result, so please anyone who really knows there stuff enlighten me!!
All of the following transformation permutations give the same result:
<!--
<xsl:template match="/*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:copy-of select="*"/>
</xsl:template>-->
<!-- IdentityTransform -->
<!--<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>-->
<!--
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>-->
<!-- XSLT Template to copy anything, priority="-1" -->
<!--<xsl:template match="/|*|@*|node()|@*/node()" priority="-1">
<xsl:copy>
<xsl:apply-templates select="*|@*|node()|@*/node()"/>
</xsl:copy>
</xsl:template>-->
<!--
<xsl:template
match="*|@*|comment()|processing-instruction()|text()">
<xsl:copy>
<xsl:apply-templates
select="*|@*|comment()|processing-instruction()|text()"/>
</xsl:copy>
</xsl:template>-->
<!--
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:copy>-->
<!--
<xsl:template match="metadata/rf/exam">
<exam>some text</exam>
</xsl:template>-->
<!--
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
-->
<!--
<xsl:template match="*/text()">
<xsl:copy-of select="."/>
</xsl:template>
-->
<!--
<xsl:template
match="*|@*|comment()|processing-instruction()|text()">
<xsl:copy>
<xsl:apply-templates
select="*|@*|comment()|processing-instruction()|text()"/>
</xsl:copy>
</xsl:template>
-->
Thanks. Adam
|