Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: xsl copy [Thread Next] Re: xsl copyTo: NULL Date: 11/13/2008 10:39:00 AM That works great. Thanks "Dimitre Novatchev" <dnovatchev@c...> wrote in message news:Omnqi%23TRJHA.4512@T...... > > "Gan Kol" <gankol@g...> wrote in message > news:uYgPV9PRJHA.5080@T...... >> 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"> > > <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= > "*[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 > | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
