[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

merging two xml files by a generic way - 2

Subject: merging two xml files by a generic way - 2
From: Braumüller, Hans <H.Braumueller@xxxxxxxxxxxx>
Date: Wed, 28 Jun 2006 16:06:03 +0200
xsl concat two xml files
Hello again,

i include my bad solution, because i think it is very redundant and i must
adapt my source(s).xml with ids that have a corresponding in the doc2 for
getting the specific language titles.

Do you have a better approach ?

Here we go:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name="p_sLanguage" select="'en'"/>
  <!-- Default Path im Attribut select, wenn kein Parameter |bergeben wurde
-->
  <xsl:param name="p_sPathLng" select="'doc2_'"/>
  <xsl:param name="doc2file"
select="concat($p_sPathLng,$p_sLanguage,'.xml')"/>

  <!-- import der spezifischen Anzeige-Eigenschaften anhand des |bergebebenen
Parameters p_sLanguage  -->
  <!-- mit zweiter Option document('') wird f|r die document() Funktion die
Base-Uri relative zum Stylesheets deklariert   <xsl:variable
name="objApplicationProperties" select="document()"/>-->
  <xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/>
  <xsl:variable name="doc2" select="document($doc2file,document(''))"/>

  <!-- Start f|r alle -->
  <xsl:template match="/">
    <xsl:apply-templates>
      <xsl:with-param name="doc2node" select="$doc2/Root"/>
    </xsl:apply-templates>
  </xsl:template>


 <!--Start f|r nach variablem Root-Element -->
  <xsl:template match="/*">
    <xsl:param name="doc2node"/>
    <xsl:copy>
      <!-- Attribute -->
      <xsl:apply-templates select="@*" />

      <!-- erstmal direkt abfragen   -->
      <xsl:choose>
        <xsl:when test=" name() = 'Templates' ">
          <xsl:apply-templates>
            <xsl:with-param name="doc2node" select="$doc2node/Templates"/>
          </xsl:apply-templates>
        </xsl:when>
        <xsl:when test=" name() = 'Infos' ">
          <xsl:apply-templates>
            <xsl:with-param name="doc2node" select="$doc2node/Infos"/>
          </xsl:apply-templates>
        </xsl:when>
      </xsl:choose>

    </xsl:copy>
  </xsl:template>

  <!-- Identity copy of source-->
  <xsl:template match="*">
    <xsl:param name="doc2node"/>
    <!-- <xsl:varaible name="count" select="count()"/> -->
    <xsl:copy>
      <xsl:apply-templates select="@*[not(name()='id')]" />

       <xsl:if test=" normalize-space(@id) !='' ">
        <!-- searching for title in doc2 -->
        <xsl:call-template name="titleDoc2">
        <xsl:with-param name="id" select="@id"/>
        <xsl:with-param name="doc2node" select="$doc2node"/>
      </xsl:call-template>
      </xsl:if>

      <!-- go traversing  -->
      <xsl:apply-templates>
        <xsl:with-param name="doc2node" select="$doc2node"/>
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>


<!-- Identity copy of doc2 only for @title with corresponding id from
source-->
  <xsl:template match="*" mode="lng">
    <xsl:param name="id"/>

    <xsl:choose>
      <!-- find by @param id -->
      <xsl:when test="normalize-space($id) = normalize-space(@id)">
       <xsl:apply-templates select="@title" />
	 <!--
	open question - how can i break the recursive traverse of source node, after
getting here the title from doc2
	-->
      </xsl:when>
      <!-- search -->
      <xsl:otherwise>
        <xsl:apply-templates mode="lng">
          <xsl:with-param name="id" select="$id"/>
        </xsl:apply-templates>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Title-Rule to find title  -->
  <xsl:template name="titleDoc2">
    <xsl:param name="id"/>
    <xsl:param name="doc2node"/>
       <xsl:apply-templates select="$doc2node" mode="lng">
        <xsl:with-param name="id" select="$id"/>
      </xsl:apply-templates>
  </xsl:template>

  <!-- Identity Kopie der Attribute vom Source oder Doc2 f|r Titel -->
  <xsl:template match="@*">
    <xsl:copy-of select="."/>
  </xsl:template>


</xsl:stylesheet>


Doc1 Example -----------
<?xml version="1.0" encoding="iso-8859-1"?>
<Templates>
  <Template name="CSV" id="CSV1">
    <Element name="head" id="CSV2">
      <Leaf name="Maprule" action="refresh,ins,del,save"  id="CSV3"
title="DE_defaultMaprule">
        <Attribute name="match" editable="manual" title="DE_CSV4" id="CSV4"/>
        <Attribute name="value" editable="drop" refersto="KOPF"  id="CSV5"/>
      </Leaf>
    </Element>
  </Template>
  <Template name="CSV_HO" id="CSV_HO1">
    <Element name="head" id="CSV_HO2">
      <Leaf name="Maprule" id="CSV_HO3">
        <Attribute name="match"  id="CSV_HO4"/>
        <Attribute name="value" editable="drop" refersto="KOPF"
id="CSV_HO5"/>
      </Leaf>
    </Element>
  </Template>
</Templates>

Doc2 Example ----------- Beginning with Root -Element inside Templates the
same structure as doc1
only with the language specific values for attribute title
<?xml version="1.0" encoding="iso-8859-1"?>
<Root>
  <Templates file="templates.xml">
    <Template  id="CSV1">
      <Element name="head" title="1HeadElement" id="CSV2">
        <Leaf name="Maprule" id="CSV3">
          <Attribute name="match" title="1match" id="CSV4"/>
          <Attribute name="value"  title="1value" id="CSV5"/>
        </Leaf>
      </Element>
      <!-- following element nodes() -->
    </Template>
    <Template name="CSV_HO" id="CSV_HO1">
      <Element name="head" title="2HeadElement"  id="CSV_HO2">
        <Leaf name="Maprule"  id="CSV_HO3">
          <Attribute name="match" title="2match"  id="CSV_HO4"/>
          <Attribute name="value" title="2value"  id="CSV_HO5"/>
        </Leaf>
      </Element>
      <!-- following element nodes() -->
    </Template>
  </Templates>
  <!-- another sections to put titles from other sources, following  infos.xml
-->
  <Infos file="infos.xml">
    <Template name="KOPF">
      <Element name="KOPF_INDEX" title="KOPF_INDEX"/>
      <!-- etc-->
    </Template>
    <Template name="POS">
      <Element name="POSITION_IDX" title="POSITION_IDX"/>
      <!-- etc-->
    </Template>
  </Infos>
  <!-- etc-->
</Root>

Output Example --------------------------------------------
<Templates>
<Template name="CSV">
<Element name="head" title="1HeadElement">
<Leaf name="Maprule" action="refresh,ins,del,save" title="DE_defaultMaprule">
<Attribute name="match" editable="manual" title="1match"></Attribute>
<Attribute name="value" editable="drop" refersto="KOPF"
title="1value"></Attribute>
</Leaf>
</Element>
</Template>
<Template name="CSV_HO">
<Element name="head" title="2HeadElement">
<Leaf name="Maprule">
<Attribute name="match" title="2match"></Attribute>
<Attribute name="value" editable="drop" refersto="KOPF"
title="2value"></Attribute>
</Leaf>
</Element>
</Template>
</Templates>

Thank you for help,
please excuse my signature below.
The company where i work put it automatically on my mails.

Greetings from Hamburg,

Hans Braum|ller
http://www.hanseorga.de





-------------------------------------------------------------------------

Profitieren Sie von unseren kostenlosen Informationsveranstaltungen
zum Thema:

  ----- ----- ----- ----- ----- ----- ---- -----

"Liquiditaetsmanagement und Treasury in SAP."

am 29. Juni 2006: Duesseldorf, Radisson SAS Hotel.

----- ----- ----- ----- ----- ----- ---- -----

F|r weitere Informationen und zu den Anmeldeformularen:

http://www.hanseorga.de/deutsch/framesets/veranstaltungen/frameroadshow.html
Wir freuen uns |ber Ihre Teilnahme!

-------------------------------------------------------------------------

Diese E-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte
Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail
irrtuemlich erhalten haben, informieren Sie bitte sofort den Absender und
vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte
Weitergabe dieser E-Mail ist nicht gestattet.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.