Vaish

 
HiHi
1.
WWhen I use first xsl file to arrange the sturcture of xml  and second xsl file to remove all empty nodes and elements, the output file I am getting with no empty nodes and elements, Thats fine.
I I have templates in my first xsl files, these templates only appear if elements under these template has value otherwise it is not appear in the out putxml file
 
S So I want one element <AdditionalTransactionDetails> to escape in the output file if the template <SDLT4> has any elements with value. I have pasted below the following
    
a) Fragment of first xsl File
      b) Full code of second xsl file
      c) Fragment of output xml file
 
- 1. Xsl file - Fragment
 
 
 <xsl:template match="SDLT4">
 <AdditionalTransactionDetails> <! This elemnt should appear in the output file if any of the element has value under SDLT4 template    -->
             <TotalConsideration>
                    <xsl:attribute name="ChattelsAndMoveables">
                     <xsl:apply-templates select="TotalConsiderationChattels1" />
                     </xsl:attribute>
            </TotalConsideration>
      <PropertyUse>
                 <Office>
                   <xsl:apply-templates select="PropertyUseOffice2" />
                   </Office>
        </PropertyUse>
-               <PurchaserDescription>
                <xsl:apply-templates select="PurchaserDescriptionD9" />
                </PurchaserDescription>
    </AdditionalTransactionDetails><! Ends Here-->
          <AboutTheLease>
                  <Property>
                        <PropertyType>
                               <xsl:apply-templates select="PropertyType10" />
                           </PropertyType>
                    <AddressOfLand>
                         <PostCode>
                                <xsl:apply-templates select="PostCode11" />
                          </PostCode>
                        <HouseNumber>
                               <xsl:apply-templates select="HouseNumber11" />
                          </HouseNumber>
                     </AddressOfLand>
-                 </Property>
                <LeaseDetails>
                      <LeaseType>
                          <xsl:apply-templates select="TypeOfLease18" />
                       </LeaseType>
-          </LeaseDetails>
          <AdditionalLeaseInfo>
                        <TermsSurrendered>
                             <xsl:apply-templates select="TermsSurrendered28" />
                          </TermsSurrendered>
-          </AdditionalLeaseInfo>
        </AboutTheLease>
     </SDLT4>
  </xsl:template>
2.
2. 2. Xsl file - To remove empty elements and nodes
 
< xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes" />
   <xsl:template match="node()|@*">
  <xsl:copy>
  <xsl:apply-templates select="node()|@*" />
  </xsl:copy>
  </xsl:template>
  <xsl:template match="node()[not(@*[normalize-space(.)]) and not(normalize-space(.)) and not(self::additionalTransactionDetails)]" />
  </xsl:stylesheet>
 n
 
    (Note : I have tried this "node()............(self::additionalTransactionDetails)] as above but still I didnt get this element in the output file)
 
2. 3. Output Xml file - Fragment -
 
<<Body>
I < envelope>
<   <SDLT>
        -----------------
---------------------
---------------------
-------------------- 
      <SupplementarySections>
  <SDLT2Count>0</SDLT2Count>
  <SDLT3Count>0</SDLT3Count>
  <SDLT4Count>1</SDLT4Count>
  </SupplementarySections>
  <SDLT4>
<!--  I need to get this element in the output file  <AdditionalTransactionDetails/>   -->
    <AboutTheLease>
             <Property>
                    <PropertyType>02</PropertyType>
             <AddressOfLand>
                  <PostCode>IG3 RT</PostCode>
                        <HouseNumber>4q</HouseNumber>
            </AddressOfLand>
                      <LAnumber>4</LAnumber>
                   <TitleNumber>7</TitleNumber>
                    <NLPGUPRN>NL</NLPGUPRN>
             </Property>
       <AdditionalLeaseInfo>
                  <TermsSurrendered>no</TermsSurrendered>
      </AdditionalLeaseInfo>
       </AboutTheLease>
    </SDLT4>
  </SDLT>
  </IRenvelope>
  </Body>
  </GovTalkMessage>
 
 
 



Re: XML and the .NET Framework How to allow one empty element and remove all other empty nodes,elements etc from the source xml?

Dimitre_Novatchev - MSFT

Sorry,

I may have some guesses as what is wanted, but I'd rather not guess.

Please, re-formulate: simply, unambiguously, in a compact form.

Do not relate to your previous problem -- this is a new thread and people should not have to read previous threads in order to understand the problem being described. Just provide a very simple, complete but as short as possible, example of what you want to achieve.

I strongly believe people should learn how to define problems in this forum. Due to poor problem definition there is now enormous wait and wasted time in this forum -- let's make this more efficient.

Cheers,
Dimitre Novatchev





Re: XML and the .NET Framework How to allow one empty element and remove all other empty nodes,elements etc from the source xml?

Vaish

Hi

Ok. How to remove all empty nodes and elements except <AdditionalTransactionDetails> element from the source xml file.

Thank you






Re: XML and the .NET Framework How to allow one empty element and remove all other empty nodes,elements etc from the source xml?

StarlingJW

The first stylesheet added the element AdditionalTransactionDetails but the second stylesheet has an exception case ONLY for element name additionalTransactionDetails. Case matters.

It should be simpler to combine the two stylesheets but not now. Later. John Starling.




Re: XML and the .NET Framework How to allow one empty element and remove all other empty nodes,elements etc from the source xml?

Vaish

Hi

Its just a spelling mistake in the posting but the actual code doesn't work

Thank you






Re: XML and the .NET Framework How to allow one empty element and remove all other empty nodes,elements etc from the source xml?

Dimitre_Novatchev - MSFT

I noticed that there is a default namespace in the xml file being processed.

THis is a very FAQ. Please, search for "default namespace XSLT".

Here's the same code, now adjusted for names in a default namespace:

When this transformation:

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:def="my:default"

>

<xsl:output omit-xml-declaration="yes" indent="yes"/>

<xsl:strip-space elements="*"/>

<xsl:template match="node()|@*">

<xsl:copy>

<xsl:apply-templates select="node()|@*"/>

</xsl:copy>

</xsl:template>

<xsl:template match="node()

[not(@*[normalize-space()])

and

not(normalize-space())

and

not(self::def:Additional)

]"/>

</xsl:stylesheet>

is applied on this xml document:

<doc>

<Table>

<Title> </Title>

</Table>

<Additional xmlns="my:default"/>

<xxx yyy=""/>

<zzz ttt="t"/>

<a>

<b>c</b>

</a>

</doc>

the desired result is produced:

<doc>

<Additional xmlns="my:default" />

<zzz ttt="t" />

<a>

<b>c</b>

</a>

</doc>

Hope this helped.

Cheers,
Dimitre Novatchev





Re: XML and the .NET Framework How to allow one empty element and remove all other empty nodes,elements etc from the source xml?

Vaish

Hi

Thanks a Lot. It works

vaish