Need help in creating XSLT, i do have Source and Target XML

You need to assign a prefix to each namespace used by the source document, and use the appropriate prefix when addressing elements in the source document. Here’s a correction of your stylesheet:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/"
exclude-result-prefixes="soap dir">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>

<xsl:template match="https://stackoverflow.com/">
    <xsl:apply-templates select="soap:Envelope/soap:Body/dir:a/dir:b/dir:c/dir:d"/>
</xsl:template> 

<xsl:template match="dir:d">    
    <d>
        <xsl:for-each select="dir:e">
            <e>
                <xsl:value-of select="@MemberID"/>                 
            </e>
        </xsl:for-each>
    </d>
</xsl:template>

</xsl:stylesheet>

This will produce the following result :

<?xml version="1.0" encoding="utf-8"?>
<d>
  <e>1</e>
  <e>2</e>
  <e>3</e>
</d>

Of course, you could simplify this to:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/"
exclude-result-prefixes="soap dir">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>

<xsl:template match="https://stackoverflow.com/">
    <d>
        <xsl:for-each select="soap:Envelope/soap:Body/dir:a/dir:b/dir:c/dir:d/dir:e">
            <e>
                <xsl:value-of select="@MemberID"/>                 
            </e>
        </xsl:for-each>
    </d>
</xsl:template> 

</xsl:stylesheet>

To achieve the required output, change:

            <e>
                <xsl:value-of select="@MemberID"/>                 
            </e>

to:

            <e ID="{@MemberID}"/>

Leave a Comment