Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT: I am trying to flatten XML element based on child element name using XSLT 1.0
    primarykey
    data
    text
    <p>am trying to flatten an XML element based on a child element name using XSLT 1.0</p> <p>The source XML:</p> <pre><code>&lt;Contact&gt; &lt;ContactPurpose&gt; &lt;PurposeAsPlainText xmlns="cds_dt"&gt;Call&lt;/PurposeAsPlainText&gt; &lt;/ContactPurpose&gt; &lt;ContactPurpose&gt; &lt;PurposeAsEnum xmlns="cds_dt"&gt;Call&lt;/PurposeAsEnum&gt; &lt;/ContactPurpose&gt; &lt;/Contact&gt; </code></pre> <p>Should be transformed into the following XML:</p> <pre><code>&lt;Contact&gt; &lt;ContactPurpose&gt;O&lt;/ContactPurpose&gt; &lt;ContactPurpose&gt;Call&lt;/ContactPurpose&gt; &lt;/Contact&gt; </code></pre> <p>The Logic is:</p> <p>IF the child element name is “PurposeAsPlainText “ THEN set “O” for Other in destination</p> <p>ELSEIF the child element name is “PurposeAsEnum” THEN copy the source value to destination</p> <p><strong>EDIT 1</strong>: I could be more clear as none of the solutions flattened the xml, please see revised source and dest XML.</p> <p><strong>EDIT 2</strong>: Here is the XML I was testing against. The two tranform solutions below actually do work on my original xml but not the revised xml that I was testing using .NET 4.0 XslCompiledTransform. Or should I make a new question?</p> <pre><code>&lt;MyDS xmlns="cds" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;PatientRecord&gt; &lt;Demographics&gt; &lt;Contact&gt; &lt;ContactPurpose&gt; &lt;PurposeAsPlainText xmlns="cds_dt"&gt;Call&lt;/PurposeAsPlainText&gt; &lt;/ContactPurpose&gt; &lt;ContactPurpose&gt; &lt;PurposeAsEnum xmlns="cds_dt"&gt;Call&lt;/PurposeAsEnum&gt; &lt;/ContactPurpose&gt; &lt;/Contact&gt; &lt;/Demographics&gt; &lt;/PatientRecord&gt; &lt;/MyDS&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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