Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hopefully something like this is what you are looking for (I reuse parts of your solution): </p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output indent="yes" /&gt; &lt;!-- Define keys --&gt; &lt;xsl:key name="kPropertyByName" match="Property[contains(@Name, '.')]" use="concat(generate-id(..), '|', substring-before(@Name,'.'))"/&gt; &lt;!-- Define variables --&gt; &lt;xsl:variable name="vDestinationArray" select="'A,B,C'" /&gt; &lt;xsl:template match="Data" &gt; &lt;Root&gt; &lt;xsl:apply-templates /&gt; &lt;/Root&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Object" &gt; &lt;ObjectData&gt; &lt;!-- (rule 1.)--&gt; &lt;xsl:apply-templates select="Property[not(contains(@Name, '.'))]"/&gt; &lt;!-- For each 'Property'-element that *does* contain separator '.' in 'Name'-attribute, and *does* NOT exists in 'array'-variable (rule 2.) --&gt; &lt;xsl:for-each select="Property[generate-id(.) = generate-id(key('kPropertyByName', concat(generate-id(..), '|', substring-before(@Name,'.')))[1]) and not ( contains( concat(',',$vDestinationArray,','),concat(',',substring-before(@Name,'.'),',')) ) ] "&gt; &lt;xsl:apply-templates select="." mode ="parent" /&gt; &lt;/xsl:for-each&gt; &lt;!-- For each 'Property'-element that *does* contain separator '.' in 'Name'-attribute, and *does* exists in 'array'-variable and Value attribute is not '' (rule 3) --&gt; &lt;xsl:for-each select="Property[generate-id(.) = generate-id(key('kPropertyByName', concat(generate-id(..), '|', substring-before(@Name,'.')))[1]) and contains( concat(',',$vDestinationArray,','),concat(',',substring-before(@Name,'.'),',')) and @Value != '' ] "&gt; &lt;!-- only for firs one (rule 3-b.)--&gt; &lt;xsl:if test="position() = 1" &gt; &lt;Destination&gt; &lt;xsl:element name="Type"&gt; &lt;xsl:value-of select="substring-before(@Name,'.')" /&gt; &lt;/xsl:element&gt; &lt;xsl:apply-templates mode="replace" select="../Property[ substring-before(current()/@Name,'.') = substring-before(./@Name,'.') and @Value != '' ]"/&gt; &lt;/Destination&gt; &lt;/xsl:if&gt; &lt;/xsl:for-each&gt; &lt;/ObjectData&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Property[not(contains(@Name, '.'))]" &gt; &lt;xsl:element name="{@Name}"&gt; &lt;xsl:value-of select="@Value"/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Property[@Value != '']" mode ="replace"&gt; &lt;xsl:element name="{substring-after(@Name,'.')}"&gt; &lt;xsl:value-of select="@Value"/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Property[(contains(@Name, '.'))]" mode ="child"&gt; &lt;xsl:element name="{substring-after(@Name,'.')}"&gt; &lt;xsl:value-of select="@Value"/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Property[(contains(@Name, '.'))]" mode ="parent"&gt; &lt;xsl:element name="{substring-before(@Name,'.')}"&gt; &lt;xsl:apply-templates mode="child" select="../Property[ substring-before(current()/@Name,'.') = substring-before(./@Name,'.')]"/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>This will generate the requested output (as I understood it).</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;Root&gt; &lt;ObjectData&gt; &lt;Id&gt;001&lt;/Id&gt; &lt;P&gt; &lt;Id&gt;Id P&lt;/Id&gt; &lt;Description&gt;Descr P&lt;/Description&gt; &lt;/P&gt; &lt;Destination&gt; &lt;Type&gt;A&lt;/Type&gt; &lt;Id&gt;Id A&lt;/Id&gt; &lt;Description&gt;Descr A&lt;/Description&gt; &lt;/Destination&gt; &lt;/ObjectData&gt; &lt;ObjectData&gt; &lt;Id&gt;002&lt;/Id&gt; &lt;P&gt; &lt;Id&gt;Id P&lt;/Id&gt; &lt;Description&gt;Descr P&lt;/Description&gt; &lt;/P&gt; &lt;Destination&gt; &lt;Type&gt;B&lt;/Type&gt; &lt;Id&gt;Id B&lt;/Id&gt; &lt;Description&gt;Descr B&lt;/Description&gt; &lt;/Destination&gt; &lt;/ObjectData&gt; &lt;/Root&gt; </code></pre> <p>(This was a little harder than expected. The stylesheet could need a little beautification/ improvement, but it's a little late now.)</p>
    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. 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.
    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