0

I have this XML with namespace and i need to extract on segment "NewDataSet" I have a xsl code but it's not works

<?xml version="1.0" encoding="UTF-8"?>
<Listado_OrdenesResponse xmlns='http://tempuri.org/' 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'>
	<Listado_OrdenesResult>
		<diffgr:diffgram xmlns:diffgr='urn:schemas-microsoft-com:xml-diffgram-v1' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
			<NewDataSet xmlns=''>
				<RowNum diffgr:id='RowNum1' msdata:rowOrder='0'>
					<MATNR>10000101</MATNR>    					<AUFNR>731200000047</AUFNR>
					<MENGE>385</MENGE>
					<MEINS>G</MEINS>
				</RowNum>
				<RowNum diffgr:id='RowNum2' msdata:rowOrder='1'>
					<MATNR>45000528</MATNR>
					<AUFNR>731200000047</AUFNR>
					<MENGE>540</MENGE>
					<MEINS>KG</MEINS>
				</RowNum>
			</NewDataSet>
		</diffgr:diffgram>
	</Listado_OrdenesResult>
</Listado_OrdenesResponse>

I need to extract like this segment , NewDataSet.

<NewDataSet> <RowNum>
				<MATNR>10000101</MATNR>
					<AUFNR>731200000047</AUFNR>
				</RowNum>
			<RowNum>
					<MATNR>45000528</MATNR>
					<AUFNR>731200000047</AUFNR>
				</RowNum>
			</NewDataSet>
<!-- Need To Extract -->

I have this code but the return is not as expected.

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Studio 2018 (https://www.liquid-technologies.com) -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="xml" indent="yes" encoding="UTF-8" />

    <xsl:template match="//NewDataSet">
            <xsl:copy-of select="."/>
    </xsl:template>
    <xsl:template match="text()"/>
</xsl:stylesheet>

When I run the above XSL, I got this XML. I will have the segment without namespace

<?xml version="1.0" encoding="UTF-8"?>
<RowNum xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
        xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
        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"
        diffgr:id="RowNum1"
        msdata:rowOrder="0">
					<MATNR>10000101</MATNR>
					<AUFNR>731200000047</AUFNR>
					<MENGE>385</MENGE>
					<MEINS>G</MEINS>
				</RowNum>
<RowNum xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
        xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
        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"
        diffgr:id="RowNum2"
        msdata:rowOrder="1">
					<MATNR>45000528</MATNR>
					<AUFNR>731200000047</AUFNR>
					<MENGE>540</MENGE>
					<MEINS>KG</MEINS>
				</RowNum>

Can you Help me?

1
  • The first segment you have has fewer elements than the segment (i.e. the first does not have MENGE or MEINS) so it is not quite clear what you want, whether you want to have all the child elements of a RowNum or only certain ones like MATNR and AUFNR. Commented Feb 18, 2018 at 13:23

1 Answer 1

0

In XSLT 2.0, use <xsl:copy-of select="XXXX" copy-namespaces='no'/>.

In XSLT 1.0 you need to use a variant of the identity template, copying elements using <xsl:element name="{local-name()}" namespace="namespace-uri()"/>.

Please don't ask XSLT questions without saying which version you are using, as many things are easier with XSLT 2.0 or 3.0!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.