Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 

Go Back   XSL - XML - RSS Forums > XSLForum: Main > XSL Coding General

Tags:



Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-13-2008, 04:08 PM
Gan Kol
 
Posts: n/a

Default Re: xsl copy



That works great. Thanks
"Dimitre Novatchev" <dnovatchev@cnntp.org> wrote in message
news:Omnqi%23TRJHA.4512@TK2MSFTNGP02.phx.gbl...
>
> "Gan Kol" <gankol@gmail.com> wrote in message
> news:uYgPV9PRJHA.5080@TK2MSFTNGP05.phx.gbl...
>> Hi,
>>
>> I have an xml something like this.
>> <Test>
>> <Type>New</Type>
>> <Lang>
>> <English>
>> <Screenplay>test11</Screenplay>
>> <Script>script11</Script>
>> </English>
>> <ExpiryDate>2009-10-10</ExpiryDate>
>> </Lang>
>> <StudentNumber>1234333</StudentNumber>
>> <RequestDate>2008-10-10</RequestDate>
>> <FirstName>David</FirstName>
>> <MiddleName>-</MiddleName>
>> <LastName>Burges</LastName>
>> <Qualifier>-</Qualifier>
>> <Status></Status>
>> </Test>
>>
>> I would like to have an output xml as the same structure as above, but
>> Omit the elements if a "-" is the only data in the element (for eg.
>> should keep the date element expiry date, but omit MiddleName, Qualifier)
>> Since i dont know about the xml data and structure inside the xml when
>> doing the xsl transformation, i tried using xsl copy instead of select,
>> but didnt know how to check for the conditions.

>
>
> The following override of the identity transformation is a natural
> solution:
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xslutput 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=
> "*[text() and not(node()[not(self::text())])]
> [normalize-space() = '-']"/>
> </xsl:stylesheet>
>
> When applied on the originally specified xml document:
>
> <Test>
> <Type>New</Type>
> <Lang>
> <English>
> <Screenplay>test11</Screenplay>
> <Script>script11</Script>
> </English>
> <ExpiryDate>2009-10-10</ExpiryDate>
> </Lang>
> <StudentNumber>1234333</StudentNumber>
> <RequestDate>2008-10-10</RequestDate>
> <FirstName>David</FirstName>
> <MiddleName>-</MiddleName>
> <LastName>Burges</LastName>
> <Qualifier>-</Qualifier>
> <Status></Status>
> </Test>
>
> the wanted result is produced:
>
> <Test>
> <Type>New</Type>
> <Lang>
> <English>
> <Screenplay>test11</Screenplay>
> <Script>script11</Script>
> </English>
> <ExpiryDate>2009-10-10</ExpiryDate>
> </Lang>
> <StudentNumber>1234333</StudentNumber>
> <RequestDate>2008-10-10</RequestDate>
> <FirstName>David</FirstName>
> <LastName>Burges</LastName>
> <Status/>
> </Test>
>
> Hope this helped.
>
> Cheers,
> Dimitre Novatchev
>



Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Contact Us -|- XSL - XML - RSS Forums -|- Archive -|- Top -|-Rules/Disclaimer-|-Help/Support -|-Advertise
© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
All times are GMT. The time now is 05:41 PM.
Style Developed by Epic Designz