[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Merging changes via ID
It seemed easy enough and a texbook example straight from the FAQ at the beginning, but I find it hard to combine two XML files in XSLT 2: a new, updated, English original and an old, translated, variant Or maybe I'm just tired. I want the new file to reflect the structure of the updated, English file and have the text content of the translated one. The XML files are derived from Docbook. So for example from these two: doc1.xml: <article xmlns="http://docbook.org/ns/docbook" version="5.0" xml:id="SAMPLE_EN"> <info xml:id="intro"> <title>Welcome to the Docbook</title> </info> <section xml:id="s01"> <title>Inline Markup and Images</title> <para>This is a sample showing that <oXygen/> can be used to edit documents in conformity with the dockbookx.dtd.</para> <para>In order to preview this text in a Web browser, you have to choose the <code>Docbook HTML</code> transformation scenario. For this press the <guibutton>Configure transformation scenario</guibutton> button or the shortcut <keycap>CTRL+SHIFT+C</keycap> or (<keycap>META+SHIFT+C</keycap> on Mac OS X), then select the scenario. Press <guibutton>Ok</guibutton>.</para> <para>To apply the stylesheet you have to press the "Apply transformation scenario" button or to press <keycap>CTRL+SHIFT+T</keycap> (<keycap>META+SHIFT+T</keycap> on Mac OS X). </para> </section> <section xml:id="s02"><title>only english</title><para>only english</para></section> <section xml:id="s04"><title>Nesting sample</title> <para>to illustrate nesting issues</para> </section> </article> doc2.xml: <article xmlns="http://docbook.org/ns/docbook" version="5.0" xml:id="SAMPLE"> <info xml:id="intro"> <title>Wprowadzenie do Docbook</title> </info> <section xml:id="s01"> <title>Formatowanie i Obrazki</title> <para>Oto przyklad ze <oXygen/> moze byc uzwany do edycji dokumentow zgodnych z dockbookx.dtd.</para> <para>Aby obejrzec te instrukcje w przegladarce WWW, wybierz nastepujacy scenariusz transformacji: <code>Docbook HTML</code>. </para> </section> <section xml:id="s03"><title>tylko polski</title><para>tylko polski</para></section> <section xml:id="s04"><title>Przyklad zagniezdzania</title> <para>Aby zilustrowac problemy z zagniezdzaniem.</para> </section> </article> Desired output: <article xmlns="http://docbook.org/ns/docbook" version="5.0" xml:id="SAMPLE_EN"> <info xmlns="http://docbook.org/ns/docbook" xml:id="intro"> <title>Wprowadzenie do Docbook</title> </info> <section xmlns="http://docbook.org/ns/docbook" xml:id="s01"> <title>Formatowanie i Obrazki</title> <para>Oto przyklad ze <oXygen/> moze byc uzwany do edycji dokumentow zgodnych z dockbookx.dtd.</para> <para>Aby obejrzec te instrukcje w przegladarce WWW, wybierz nastepujacy scenariusz transformacji: <code>Docbook HTML</code>. </para> </section> <section xml:id="s04" xmlns="http://docbook.org/ns/docbook"> <title>Przyklad zagniezdzania</title> <para>Aby zilustrowac problemy z zagniezdzaniem.</para> </section> </article> So, to begin, I've created the following: <xsl:template match="*[@xml:id]"> <xsl:copy-of select="document('doc2.xml')//*[@xml:id=document('doc1.xml')//@xml:id]"/> </xsl:template> And it seems to work fine against this contrived example, but I'm pretty sure it won't work well for bigger files. My worries: the recursion is from top to bottom, so what if there are changes below and the tempate matches the whole tree at the top? It matched on ID but what about the changes for inline elements below block level that don't have an ID? Would it make processing more simple were I to generate IDs for them or should I process and match them as descendant of a given ID of a block? Other worries such as removed, added element, I've already taken care of those. Best regards, Lech Rzedzicki I appreciate any useful hints on this.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|