[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: xsl transform on xml with namespaces returns no o

Subject: RE: xsl transform on xml with namespaces returns no output
From: "Raveendran, Reshma" <Reshma.Raveendran@xxxxxxxxxxxxxxxxx>
Date: Fri, 7 Aug 2009 18:44:25 +0530
 RE: xsl transform on xml with namespaces returns no  o
Hi Martin,

Thanks a lot, the solution works perfectly!



--------------------------------
Raveendran, Reshma wrote:

> I want to apply xsl on the xml below to get a transformed xml as shown
> below.
>
> Source xml ---
>
>  <input xmlns="http://tempuri.org/">
>   <InputParams
> xmlns="http://schemas.datacontract.org/2004/07/GenericQuery">
> 	<anyType xsi:type="q1:ResultSpecPagination"
> xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
> xmlns:q1="urn:cbc:message"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>   <PageSize xmlns="">10</PageSize>
>   </anyType>
>   <anyType xsi:type="q2:AccountFilter"
> xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
> xmlns:q2="urn:cbc:clientinfo"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>  <AccountFilter xmlns="">
>   <O>101</O>
>   <F>173</A>
>   </AccountFilter>
>   </anyType>
>   <anyType xsi:type="xsd:string"
> xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">677</anyType>
>   <anyType xsi:type="xsd:string"
> xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">A</anyType>
>   </InputParams>
>   </input>
>
>
> Expected Result:
> -  <pSearch xmlns="http://tempuri.org/">
> - <p1>
>   <PageSize xmlns="">10</PageSize>
>   </p1>
> - <p2>
> -<AccountFilter xmlns="">
>   <O>101</O>
>   <F>173</F>
>   </AccountFilter>
>   </p2>
>   <p3>677</p3>
>   <p4>A</p4>
>   </pSearch>

With XSLT 2.0 you can prevent namespaces from being copied:

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:df="http://tempuri.org/"
   xmlns="http://tempuri.org/"
   xmlns:gq="http://schemas.datacontract.org/2004/07/GenericQuery"
   xmlns:sa="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
   exclude-result-prefixes="df gq sa"
   version="2.0">

   <xsl:output indent="yes"/>

   <xsl:template match="df:input">
     <pSearch>
       <xsl:apply-templates select="gq:InputParams/sa:anyType"/>
     </pSearch>
   </xsl:template>

   <xsl:template match="sa:anyType">
     <xsl:element name="p{position()}">
       <xsl:copy-of select="node()[normalize-space()]"
copy-namespaces="no"/>
     </xsl:element>
   </xsl:template>

</xsl:stylesheet>

That should do what you want.

--

	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

--------------------------------------------------------------------------
NOTICE: If received in error, please destroy, and notify sender. Sender does
not intend to waive confidentiality or privilege. Use of this email is
prohibited when received in error. We may monitor and store emails to the
extent permitted by applicable law.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.