Jump to content

Handling Cdata


Recommended Posts

Hi Folks, I have two questions:1). How to escape CDATA in your xslt script?

 <xsl:template match="/">	<![CDATA[		<xsl:apply-templates select="node()"/>		]]>	</xsl:template>

In the above code, the template inside CDATA does not get executed. What I actually want is the result from this template (<xsl:apply-templates select="node()"/>) to be returned as CDATA. For example, if the apply template returns....

 <request code=10 type="2"/>

then i want the final output to be

  <![CDATA[<request code=10 type="2"/>]]>

. But at the moment apply template is not getting executed.2). My second question is regarding the response to be transformed/decoded to CDATA or proper xml. I'm getting a response from a webservice for example:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">	<soap:Body>		<ForwardRequestResponse xmlns="http://webservices.kuoni.ch">			<ForwardRequestResult><?xml version="1.0" encoding="windows-1252"?><Response Version="2.5" From="KUEKA0" To="EBOOKERS" TermId="EB0001" Window="A" Date="04082009" Time="095322" Type="ERROR" Confirm="YES" Agent="541406" Lang="DE" UserCode="EBOO" UserType="M" UserName="EBOOKERS" UserFirstName="CH" Mode="Test"><Err SegRef="001"><ErrorNr>3706</ErrorNr><ErrorText>Datum für Flug/Transport überprüfen</ErrorText></Err></Response></ForwardRequestResult>		</ForwardRequestResponse>	</soap:Body></soap:Envelope>

Now if you look inside, <ForwardRequestResult> element the text is encoded, how can I decode it to a proper xml form i.e. without these < ? > ect ??Thanks.

Link to post
Share on other sites

I'm not sure if you can really do what you describe. The xsl:output element has a cdata-section-elements attribute that takes explicit list of element names, the contents of which is written as CDATA instead of plain text nodes. However, I'm not sure how this option reacts to an element with descendants. I believe it won't take them in account, and CDATA will only be used on text() nodes that are childs of that very element.Anyhow, for the most part, CDATA is useless anyway. It's read by XML parsers very similarly to text nodes. It only looks different in the source view to a human.As for your second question... in XSLT, you may only print out this contents as XML, but not parse it (and thus, do transformations based on it). You can print it by using disable-output-escaping in xsl:value-of like:

<xsl:value-of select="ForwardRequestResult" disable-output-escaping="yes" />

In other environments, there will be different functions for that. In PHP for example, there's , and there's also loadXML().AFAIK, strings from DOM will already have entities escaped, so in DOM, you should be able to do something like:

$soapDoc = new DOMDocument;$soapDoc->load('soap.xml');$frr = new DOMDocument;$frr->loadXML($soapDoc->getElementsByTagName('ForwardRequestResult')->item(0)->nodeValue);//$frr now contains a document representing the contents of the ForwardRequestResult element

Link to post
Share on other sites

Hi Boen, Thanks for your reply, Regardign question 1), I have tried according to what you said but it didn't work. Here is my example xsl script:

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">	<xsl:strip-space elements="soap:*"/>	<xsl:output method="xml" version="1.0" encoding="ISO-8859-1"  cdata-section-elements="request"/>	<xsl:template match="/">		<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">			<xsl:attribute name="xmlns:xsi">http://www.w3.org/2001/XMLSchema-instance</xsl:attribute>			<xsl:attribute name="xmlns:xsd">http://www.w3.org/2001/XMLSchema</xsl:attribute>			<soap:Header>				<authentication xmlns="http://webservices.xx.xx">					<userid>xxx</userid>					<password>xxx</password>				</authentication>			</soap:Header>			<soap:Body>			<ForwardRequest xmlns="http://webservices.xx.xx">						<request> <!-- CDATA would contain Request element and all its decendents -->				<xsl:apply-templates select="Request"/>			</request>			</ForwardRequest>				<!--xsl:copy-of select="node()"></xsl:copy-of-->			</soap:Body>		</soap:Envelope>	</xsl:template>	<xsl:template match="Request">		<xsl:element name="{local-name()}" namespace="http://webservices.xx.xx">			<xsl:copy-of select="@*"/>			<xsl:copy-of select="*"/>		</xsl:element>	</xsl:template></xsl:stylesheet>

The above script on this following input:

<?xml version="1.0" encoding="ISO-8859-1"?><Request SubType="CHECK" Type="BOOK" Version="2.5" From="EBOOKERS" To="KUEKA0" TermId="1245322042390" Window="A" Date="18062009" Time="124722" Confirm="YES" Agent="" Lang="DE" UserCode="123456" UserType="M" UserName="EBOOKERS" UserFirstName="CH" Mode="Test">	<Fab Key="K0000 00">		<TOCode>KUON</TOCode>		<Catalog>NEFB</Catalog>		<Creator>CTS</Creator>		<Fat ServiceType="T" SegRef="0">			<StartDate>03092009</StartDate>			<Dep>PAR</Dep>			<Arr>RAK</Arr>			<Carrier>TO</Carrier>			<FlightNr/>			<Persons>12</Persons>		</Fat>		<Fat ServiceType="T" SegRef="1">			<StartDate>10092009</StartDate>			<Dep>RAK</Dep>			<Arr>PAR</Arr>			<Carrier>TO</Carrier>			<FlightNr/>			<Persons>12</Persons>		</Fat>		<Fah ServiceType="H" SegRef="2">			<StartDate>03092009</StartDate>			<Duration>7</Duration>			<Destination>RAK</Destination>			<Product>57346V</Product>			<Room>1M</Room>			<Meal>AI</Meal>			<Persons>12</Persons>		</Fah>		<Fap ID="1">			<PersonType>M</PersonType>			<Name>AAAA</Name>		</Fap>		<Fap ID="2">			<PersonType>C</PersonType>			<Name>AAAA</Name>		</Fap>	</Fab></Request>

Produced the following output:

<?xml version="1.0" encoding="ISO-8859-1"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">	<soap:Header>		<authentication xmlns="http://webservices.kuoni.ch">			<userid>xxx</userid>			<password>xxx</password>		</authentication>	</soap:Header>	<soap:Body>		<ForwardRequest xmlns="http://webservices.xx.xx">			<request>				<Request SubType="CHECK" Type="BOOK" Version="2.5" From="EBOOKERS" To="KUEKA0" TermId="1245322042390" Window="A" Date="18062009" Time="124722" Confirm="YES" Agent="" Lang="DE" UserCode="123456" UserType="M" UserName="EBOOKERS" UserFirstName="CH" Mode="Test">					<Fab Key="K0000 00">						<TOCode>KUON</TOCode>						<Catalog>NEFB</Catalog>						<Creator>CTS</Creator>						<Fat ServiceType="T" SegRef="0">							<StartDate>03092009</StartDate>							<Dep>PAR</Dep>							<Arr>RAK</Arr>							<Carrier>TO</Carrier>							<FlightNr/>							<Persons>12</Persons>						</Fat>						<Fat ServiceType="T" SegRef="1">							<StartDate>10092009</StartDate>							<Dep>RAK</Dep>							<Arr>PAR</Arr>							<Carrier>TO</Carrier>							<FlightNr/>							<Persons>12</Persons>						</Fat>						<Fah ServiceType="H" SegRef="2">							<StartDate>03092009</StartDate>							<Duration>7</Duration>							<Destination>RAK</Destination>							<Product>57346V</Product>							<Room>1M</Room>							<Meal>AI</Meal>							<Persons>12</Persons>						</Fah>						<Fap ID="1">							<PersonType>M</PersonType>							<Name>AAAA</Name>						</Fap>						<Fap ID="2">							<PersonType>C</PersonType>							<Name>AAAA</Name>						</Fap>					</Fab>				</Request>			</request>		</ForwardRequest>	</soap:Body></soap:Envelope>

Whereas what I actually want is the following:

<?xml version="1.0" encoding="ISO-8859-1"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">	<soap:Header>		<authentication xmlns="http://webservices.kuoni.ch">			<userid>xxx</userid>			<password>xxx</password>		</authentication>	</soap:Header>	<soap:Body>		<ForwardRequest xmlns="http://webservices.xx.xx">			<request>				<![CDATA[<Request SubType="CHECK" Type="BOOK" Version="2.5" From="EBOOKERS" To="KUEKA0" TermId="1245322042390" Window="A" Date="18062009" Time="124722" Confirm="YES" Agent="" Lang="DE" UserCode="123456" UserType="M" UserName="EBOOKERS" UserFirstName="CH" Mode="Test">					<Fab Key="K0000 00">						<TOCode>KUON</TOCode>						<Catalog>NEFB</Catalog>						<Creator>CTS</Creator>						<Fat ServiceType="T" SegRef="0">							<StartDate>03092009</StartDate>							<Dep>PAR</Dep>							<Arr>RAK</Arr>							<Carrier>TO</Carrier>							<FlightNr/>							<Persons>12</Persons>						</Fat>						<Fat ServiceType="T" SegRef="1">							<StartDate>10092009</StartDate>							<Dep>RAK</Dep>							<Arr>PAR</Arr>							<Carrier>TO</Carrier>							<FlightNr/>							<Persons>12</Persons>						</Fat>						<Fah ServiceType="H" SegRef="2">							<StartDate>03092009</StartDate>							<Duration>7</Duration>							<Destination>RAK</Destination>							<Product>57346V</Product>							<Room>1M</Room>							<Meal>AI</Meal>							<Persons>12</Persons>						</Fah>						<Fap ID="1">							<PersonType>M</PersonType>							<Name>AAAA</Name>						</Fap>						<Fap ID="2">							<PersonType>C</PersonType>							<Name>AAAA</Name>						</Fap>					</Fab>				</Request>]]>			</request>		</ForwardRequest>	</soap:Body></soap:Envelope>

Just concentrate on CDATA part:

...<ForwardRequest xmlns="http://webservices.xx.xx">			<request><![CDATA[<Request ......</ForwardRequest></Request>]]>			</request>

I hope i have been able to explain properly.I haven't started on the point 2 yet, so no remarks at this stage:)Thanks.

I'm not sure if you can really do what you describe. The xsl:output element has a cdata-section-elements attribute that takes explicit list of element names, the contents of which is written as CDATA instead of plain text nodes. However, I'm not sure how this option reacts to an element with descendants. I believe it won't take them in account, and CDATA will only be used on text() nodes that are childs of that very element.Anyhow, for the most part, CDATA is useless anyway. It's read by XML parsers very similarly to text nodes. It only looks different in the source view to a human.As for your second question... in XSLT, you may only print out this contents as XML, but not parse it (and thus, do transformations based on it). You can print it by using disable-output-escaping in xsl:value-of like:
<xsl:value-of select="ForwardRequestResult" disable-output-escaping="yes" />

In other environments, there will be different functions for that. In PHP for example, there's , and there's also loadXML().AFAIK, strings from DOM will already have entities escaped, so in DOM, you should be able to do something like:

$soapDoc = new DOMDocument;$soapDoc->load('soap.xml');$frr = new DOMDocument;$frr->loadXML($soapDoc->getElementsByTagName('ForwardRequestResult')->item(0)->nodeValue);//$frr now contains a document representing the contents of the ForwardRequestResult element

Link to post
Share on other sites

I was checking some examples about cdata-section-elements attribute and found some solution.I modified my script to and now it produces my intended results:

...<ForwardRequest xmlns="http://webservices.kuoni.ch">					<request><xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>		   						<xsl:apply-templates select="Request"/><xsl:text disable-output-escaping="yes">]]</xsl:text><xsl:text disable-output-escaping="yes">></xsl:text>																					<!-- CDATA would contain Request element and all its decendents -->					</request>				</ForwardRequest>...

Thanks for the pointer anyway - really appreciated!

Hi Boen, Thanks for your reply, Regardign question 1), I have tried according to what you said but it didn't work. Here is my example xsl script:
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">	<xsl:strip-space elements="soap:*"/>	<xsl:output method="xml" version="1.0" encoding="ISO-8859-1"  cdata-section-elements="request"/>	<xsl:template match="/">		<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">			<xsl:attribute name="xmlns:xsi">http://www.w3.org/2001/XMLSchema-instance</xsl:attribute>			<xsl:attribute name="xmlns:xsd">http://www.w3.org/2001/XMLSchema</xsl:attribute>			<soap:Header>				<authentication xmlns="http://webservices.xx.xx">					<userid>xxx</userid>					<password>xxx</password>				</authentication>			</soap:Header>			<soap:Body>			<ForwardRequest xmlns="http://webservices.xx.xx">						<request> <!-- CDATA would contain Request element and all its decendents -->				<xsl:apply-templates select="Request"/>			</request>			</ForwardRequest>				<!--xsl:copy-of select="node()"></xsl:copy-of-->			</soap:Body>		</soap:Envelope>	</xsl:template>	<xsl:template match="Request">		<xsl:element name="{local-name()}" namespace="http://webservices.xx.xx">			<xsl:copy-of select="@*"/>			<xsl:copy-of select="*"/>		</xsl:element>	</xsl:template></xsl:stylesheet>

The above script on this following input:

<?xml version="1.0" encoding="ISO-8859-1"?><Request SubType="CHECK" Type="BOOK" Version="2.5" From="EBOOKERS" To="KUEKA0" TermId="1245322042390" Window="A" Date="18062009" Time="124722" Confirm="YES" Agent="" Lang="DE" UserCode="123456" UserType="M" UserName="EBOOKERS" UserFirstName="CH" Mode="Test">	<Fab Key="K0000 00">		<TOCode>KUON</TOCode>		<Catalog>NEFB</Catalog>		<Creator>CTS</Creator>		<Fat ServiceType="T" SegRef="0">			<StartDate>03092009</StartDate>			<Dep>PAR</Dep>			<Arr>RAK</Arr>			<Carrier>TO</Carrier>			<FlightNr/>			<Persons>12</Persons>		</Fat>		<Fat ServiceType="T" SegRef="1">			<StartDate>10092009</StartDate>			<Dep>RAK</Dep>			<Arr>PAR</Arr>			<Carrier>TO</Carrier>			<FlightNr/>			<Persons>12</Persons>		</Fat>		<Fah ServiceType="H" SegRef="2">			<StartDate>03092009</StartDate>			<Duration>7</Duration>			<Destination>RAK</Destination>			<Product>57346V</Product>			<Room>1M</Room>			<Meal>AI</Meal>			<Persons>12</Persons>		</Fah>		<Fap ID="1">			<PersonType>M</PersonType>			<Name>AAAA</Name>		</Fap>		<Fap ID="2">			<PersonType>C</PersonType>			<Name>AAAA</Name>		</Fap>	</Fab></Request>

Produced the following output:

<?xml version="1.0" encoding="ISO-8859-1"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">	<soap:Header>		<authentication xmlns="http://webservices.kuoni.ch">			<userid>xxx</userid>			<password>xxx</password>		</authentication>	</soap:Header>	<soap:Body>		<ForwardRequest xmlns="http://webservices.xx.xx">			<request>				<Request SubType="CHECK" Type="BOOK" Version="2.5" From="EBOOKERS" To="KUEKA0" TermId="1245322042390" Window="A" Date="18062009" Time="124722" Confirm="YES" Agent="" Lang="DE" UserCode="123456" UserType="M" UserName="EBOOKERS" UserFirstName="CH" Mode="Test">					<Fab Key="K0000 00">						<TOCode>KUON</TOCode>						<Catalog>NEFB</Catalog>						<Creator>CTS</Creator>						<Fat ServiceType="T" SegRef="0">							<StartDate>03092009</StartDate>							<Dep>PAR</Dep>							<Arr>RAK</Arr>							<Carrier>TO</Carrier>							<FlightNr/>							<Persons>12</Persons>						</Fat>						<Fat ServiceType="T" SegRef="1">							<StartDate>10092009</StartDate>							<Dep>RAK</Dep>							<Arr>PAR</Arr>							<Carrier>TO</Carrier>							<FlightNr/>							<Persons>12</Persons>						</Fat>						<Fah ServiceType="H" SegRef="2">							<StartDate>03092009</StartDate>							<Duration>7</Duration>							<Destination>RAK</Destination>							<Product>57346V</Product>							<Room>1M</Room>							<Meal>AI</Meal>							<Persons>12</Persons>						</Fah>						<Fap ID="1">							<PersonType>M</PersonType>							<Name>AAAA</Name>						</Fap>						<Fap ID="2">							<PersonType>C</PersonType>							<Name>AAAA</Name>						</Fap>					</Fab>				</Request>			</request>		</ForwardRequest>	</soap:Body></soap:Envelope>

Whereas what I actually want is the following:

<?xml version="1.0" encoding="ISO-8859-1"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">	<soap:Header>		<authentication xmlns="http://webservices.kuoni.ch">			<userid>xxx</userid>			<password>xxx</password>		</authentication>	</soap:Header>	<soap:Body>		<ForwardRequest xmlns="http://webservices.xx.xx">			<request>				<![CDATA[<Request SubType="CHECK" Type="BOOK" Version="2.5" From="EBOOKERS" To="KUEKA0" TermId="1245322042390" Window="A" Date="18062009" Time="124722" Confirm="YES" Agent="" Lang="DE" UserCode="123456" UserType="M" UserName="EBOOKERS" UserFirstName="CH" Mode="Test">					<Fab Key="K0000 00">						<TOCode>KUON</TOCode>						<Catalog>NEFB</Catalog>						<Creator>CTS</Creator>						<Fat ServiceType="T" SegRef="0">							<StartDate>03092009</StartDate>							<Dep>PAR</Dep>							<Arr>RAK</Arr>							<Carrier>TO</Carrier>							<FlightNr/>							<Persons>12</Persons>						</Fat>						<Fat ServiceType="T" SegRef="1">							<StartDate>10092009</StartDate>							<Dep>RAK</Dep>							<Arr>PAR</Arr>							<Carrier>TO</Carrier>							<FlightNr/>							<Persons>12</Persons>						</Fat>						<Fah ServiceType="H" SegRef="2">							<StartDate>03092009</StartDate>							<Duration>7</Duration>							<Destination>RAK</Destination>							<Product>57346V</Product>							<Room>1M</Room>							<Meal>AI</Meal>							<Persons>12</Persons>						</Fah>						<Fap ID="1">							<PersonType>M</PersonType>							<Name>AAAA</Name>						</Fap>						<Fap ID="2">							<PersonType>C</PersonType>							<Name>AAAA</Name>						</Fap>					</Fab>				</Request>]]>			</request>		</ForwardRequest>	</soap:Body></soap:Envelope>

Just concentrate on CDATA part:

...<ForwardRequest xmlns="http://webservices.xx.xx">			<request><![CDATA[<Request ......</ForwardRequest></Request>]]>			</request>

I hope i have been able to explain properly.I haven't started on the point 2 yet, so no remarks at this stage:)Thanks.

Link to post
Share on other sites

Hi Boen, Now I'm finding it difficult to resolve problem no 2.I'm using the following xsl script:

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:exslt="http://exslt.org/common" xmlns:datetime="http://exslt.org/dates-and-times" xmlns:func="http://exslt.org/functions" xmlns:function="http://function.com" xmlns:dyn="http://exslt.org/dynamic" xmlns:java="java" exclude-result-prefixes="xsl soap">	<xsl:output encoding="UTF-8" version="1.0" method="xml"/>	<xsl:strip-space elements="soap:*"/>	<xsl:template match="/">		<xsl:apply-templates select="soap:Envelope/soap:Body/ForwardRequestResponse"/>	</xsl:template>	<xsl:template match="ForwardRequestResponse">		<xsl:element name="{local-name()}" namespace="http://webservices.xx.xx">			<xsl:value-of select="ForwardRequestResult" disable-output-escaping="yes"/>		</xsl:element>	</xsl:template></xsl:stylesheet>

On the following input:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">	<soap:Body>		<ForwardRequestResponse xmlns="http://webservices.xx.xx">			<ForwardRequestResult><?xml version="1.0" encoding="Windows-1252"?><Response Type="ERROR" SubType="WS" Version="2.5" From="KUEKA0" To="EBOOKERS" TermId="" Window="A" Date="18062009" Time="1341" Confirm="YES" Agent="" Lang="DE" UserCode="123456" UserType="M" UserName="EBOOKERS" UserFirstName="CH"><Err><ErrorNr>9000</ErrorNr><ErrorText>Some error description </ErrorText></Err></Response></ForwardRequestResult>		</ForwardRequestResponse>	</soap:Body></soap:Envelope>

Above is the response from the WS, though some error but it does not matter, the main thing i need is the response xml in a correct format and not with ><?? etc symbols.I tried to resolve this through your mentioned technique..disable-output-escaping="yes"/> but i'm getting transformation error, and annoyingly it has no proper description.Pls help.

I'm not sure if you can really do what you describe. The xsl:output element has a cdata-section-elements attribute that takes explicit list of element names, the contents of which is written as CDATA instead of plain text nodes. However, I'm not sure how this option reacts to an element with descendants. I believe it won't take them in account, and CDATA will only be used on text() nodes that are childs of that very element.Anyhow, for the most part, CDATA is useless anyway. It's read by XML parsers very similarly to text nodes. It only looks different in the source view to a human.As for your second question... in XSLT, you may only print out this contents as XML, but not parse it (and thus, do transformations based on it). You can print it by using disable-output-escaping in xsl:value-of like:
<xsl:value-of select="ForwardRequestResult" disable-output-escaping="yes" />

In other environments, there will be different functions for that. In PHP for example, there's , and there's also loadXML().AFAIK, strings from DOM will already have entities escaped, so in DOM, you should be able to do something like:

$soapDoc = new DOMDocument;$soapDoc->load('soap.xml');$frr = new DOMDocument;$frr->loadXML($soapDoc->getElementsByTagName('ForwardRequestResult')->item(0)->nodeValue);//$frr now contains a document representing the contents of the ForwardRequestResult element

Link to post
Share on other sites

I wasn't getting any errors with your XML and XSLT... I didn't got results either though.The reason was that your ForwardRequestRespons and ForwardRequestResult elements were in a namespace (http://webservices.xx.xx) which wasn't accounted for in the XSLT.I've tested this, and it produces the right results:

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:exslt="http://exslt.org/common" xmlns:datetime="http://exslt.org/dates-and-times"				xmlns:func="http://exslt.org/functions" xmlns:function="http://function.com" xmlns:dyn="http://exslt.org/dynamic" xmlns:java="java" xmlns:tns="http://webservices.xx.xx" exclude-result-prefixes="xsl soap">	<xsl:output encoding="UTF-8" version="1.0" method="xml"/>	<xsl:strip-space elements="soap:*"/>	<xsl:template match="/">		<xsl:apply-templates select="soap:Envelope/soap:Body/tns:ForwardRequestResponse"/>	</xsl:template>	<xsl:template match="tns:ForwardRequestResponse">		<xsl:element name="{local-name()}" namespace="http://webservices.xx.xx">			<xsl:value-of select="tns:ForwardRequestResult" disable-output-escaping="yes"/>		</xsl:element>	</xsl:template></xsl:stylesheet>

BTW, regarding your other topic on how to extract CDATA - it's the same deal. With or without CDATA, XSLT will read the XML in the same fashion.

Edited by boen_robot
Link to post
Share on other sites

I figured that out already but thanks dude appreciated!

I wasn't getting any errors with your XML and XSLT... I didn't got results either though.The reason was that your ForwardRequestRespons and ForwardRequestResult elements were in a namespace (http://webservices.xx.xx) which wasn't accounted for in the XSLT.I've tested this, and it produces the right results:
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:exslt="http://exslt.org/common" xmlns:datetime="http://exslt.org/dates-and-times"				xmlns:func="http://exslt.org/functions" xmlns:function="http://function.com" xmlns:dyn="http://exslt.org/dynamic" xmlns:java="java" xmlns:tns="http://webservices.xx.xx" exclude-result-prefixes="xsl soap">	<xsl:output encoding="UTF-8" version="1.0" method="xml"/>	<xsl:strip-space elements="soap:*"/>	<xsl:template match="/">		<xsl:apply-templates select="soap:Envelope/soap:Body/tns:ForwardRequestResponse"/>	</xsl:template>	<xsl:template match="tns:ForwardRequestResponse">		<xsl:element name="{local-name()}" namespace="http://webservices.xx.xx">			<xsl:value-of select="tns:ForwardRequestResult" disable-output-escaping="yes"/>		</xsl:element>	</xsl:template></xsl:stylesheet>

BTW, regarding your other topic on how to extract CDATA - it's the same deal. With or without CDATA, XSLT will read the XML in the same fashion.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...