Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <code>xsl:import</code> to reuse your XSLT files and then use the technique explained in the @Dimitre's answer as follows: </p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:exslt="http://exslt.org/common" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="exslt"&gt; &lt;xsl:import href="phase1.xsl"/&gt; &lt;xsl:import href="phase2.xsl"/&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:variable name="intermediate"&gt; &lt;xsl:apply-templates select="/CONTACTS/CONTACT" mode="phase1"/&gt; &lt;/xsl:variable&gt; &lt;CONTACTS&gt; &lt;xsl:apply-templates select="exslt:node-set($intermediate)" mode="phase2"/&gt; &lt;/CONTACTS&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Where:</p> <ul> <li>phase1.xsl and phase2.xsl are your two xslt transforms</li> <li><p>transforms are slightly modified adding a <code>mode</code> to each template. For instance, phase1.xsl transform:</p> <p> </p> <pre><code>&lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*" mode="phase1"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="CONTACT" mode="phase1"&gt; &lt;xsl:copy&gt; &lt;Customer-ID&gt; &lt;xsl:value-of select="generate-id(.)"/&gt; &lt;/Customer-ID&gt; &lt;xsl:copy-of select="FirstName|LastName|URL"/&gt; &lt;Facebook-ID&gt; &lt;xsl:choose&gt; &lt;xsl:when test="URL"&gt; &lt;xsl:value-of select="substring-after(URL,'?id=')"/&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/Facebook-ID&gt; &lt;EMAILS&gt; &lt;xsl:apply-templates select="EMail" mode="phase1"/&gt; &lt;/EMAILS&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="EMail" mode="phase1"&gt; &lt;EMail&gt; &lt;Type&gt;&lt;xsl:value-of select="substring-before( substring-after(.,'@'), '.')"/&gt; &lt;/Type&gt; &lt;Value&gt;&lt;xsl:value-of select="."/&gt;&lt;/Value&gt; &lt;/EMail&gt; &lt;/xsl:template&gt; </code></pre> <p></p></li> </ul> <p>For phase2.xsl you will use `mode="phase2" obviously.</p> <p>When the above conditions are satisfied, and the <em>merging</em> transform is applied to your first input XML, the following output is obtained:</p> <pre><code>&lt;CONTACTS&gt; &lt;CONTACT&gt; &lt;Customer-ID&gt;d0e2&lt;/Customer-ID&gt; &lt;FirstName&gt;Ford&lt;/FirstName&gt; &lt;LastName&gt;Pasteur&lt;/LastName&gt; &lt;gmail/&gt; &lt;yahoo&gt;pasteur.ford@yahoo.com&lt;/yahoo&gt; &lt;liberto/&gt; &lt;URL/&gt; &lt;Facebook-ID/&gt; &lt;/CONTACT&gt; &lt;CONTACT&gt; &lt;Customer-ID&gt;d0e9&lt;/Customer-ID&gt; &lt;FirstName&gt;Jack&lt;/FirstName&gt; &lt;LastName&gt;Sully&lt;/LastName&gt; &lt;gmail/&gt; &lt;yahoo/&gt; &lt;liberto/&gt; &lt;URL&gt;http://www.facebook.com/profile.php?id=1000474277&lt;/URL&gt; &lt;Facebook-ID&gt;1000474277&lt;/Facebook-ID&gt; &lt;/CONTACT&gt; &lt;CONTACT&gt; &lt;Customer-ID&gt;d0e16&lt;/Customer-ID&gt; &lt;FirstName&gt;Colombo&lt;/FirstName&gt; &lt;LastName&gt;Chao&lt;/LastName&gt; &lt;gmail/&gt; &lt;yahoo/&gt; &lt;liberto&gt;chao.colombo@liberto.it&lt;/liberto&gt; &lt;URL/&gt; &lt;Facebook-ID/&gt; &lt;/CONTACT&gt; &lt;/CONTACTS&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload