tags:

views:

32

answers:

2

Hi all,

I need some help with an xsl transformation, I have no idea how to begin with it because I am a novice.

I have this xml scheme:

<?xml version="1.0" encoding="utf-8"?>
<GetUserCollectionFromSiteResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/"&gt;
<GetUserCollectionFromSiteResult>
    <GetUserCollectionFromSite>
        <Users>
            <User ID="87" Sid="S-1-5-21-2025429265-1935655697-839522115-7617" Name="Falco Lannoo" LoginName="Domain\flannoo" Email="[email protected]" Notes="" IsSiteAdmin="False" IsDomainGroup="False" />
            <User ID="31" Sid="S-1-5-21-2025429265-1935655697-839522115-2721" Name="John Smith" LoginName="Domain\jsmith" Email="[email protected]" Notes="" IsSiteAdmin="False" IsDomainGroup="False" />
        </Users>
    </GetUserCollectionFromSite>
</GetUserCollectionFromSiteResult>

And I want to transform it to this:

<ns0:userInfo xmlns:ns0="http://Sharepoint.userInfo"&gt;
    <ID>218</ID>
    <Name>Falco Lannoo</Name>
</ns0:userInfo>

So I want to select the node where the loginname = "Domain\flannoo". Anyone can help me with this transformation, it has to be in XSLT 1.0

thank you

+1  A: 

This stylesheet:

<xsl:stylesheet  version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="http://Sharepoint.userInfo"
xmlns:soap="http://schemas.microsoft.com/sharepoint/soap/directory/"
exclude-result-prefixes="soap">
    <xsl:template match="soap:User[@LoginName='Domain\flannoo']">
        <ns0:userInfo>
            <xsl:apply-templates select="@*" />
        </ns0:userInfo>
    </xsl:template>
    <xsl:template match="@*"/>
    <xsl:template match="@ID|@Name">
        <xsl:element name="{name()}">
            <xsl:value-of select="." />
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

With proper input:

<GetUserCollectionFromSiteResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/"&gt;
    <GetUserCollectionFromSiteResult>
        <GetUserCollectionFromSite>
            <Users>
                <User ID="87" Sid="S-1-5-21-2025429265-1935655697-839522115-7617" Name="Falco Lannoo" LoginName="Domain\flannoo" Email="[email protected]" Notes="" IsSiteAdmin="False" IsDomainGroup="False" />
                <User ID="31" Sid="S-1-5-21-2025429265-1935655697-839522115-2721" Name="John Smith" LoginName="Domain\jsmith" Email="[email protected]" Notes="" IsSiteAdmin="False" IsDomainGroup="False" />
            </Users>
        </GetUserCollectionFromSite>
    </GetUserCollectionFromSiteResult>
</GetUserCollectionFromSiteResponse>

Output:

<ns0:userInfo xmlns:ns0="http://Sharepoint.userInfo"&gt;
    <ID>87</ID>
    <Name>Falco Lannoo</Name>
</ns0:userInfo>
Alejandro
ok, thanks alot :)
Rise_against
@Rise_against: You're wellcome.
Alejandro
A: 

Here is an alternative to Alejandro's answer. This is mostly a question of style, but that may be relevant if you have to integrate this in a more complex stylesheet.

<xsl:stylesheet  version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="http://Sharepoint.userInfo"
xmlns:soap="http://schemas.microsoft.com/sharepoint/soap/directory/"
exclude-result-prefixes="soap">
    <xsl:template match="/">
    <xsl:apply-templates select="//soap:User[@ID='87']"/>
    </xsl:template>
    <xsl:template match="soap:User">
        <ns0:userInfo>
            <ID><xsl:value-of select="@ID"/></ID>
            <Name><xsl:value-of select="@Name"/></Name>
        </ns0:userInfo>
    </xsl:template>
</xsl:stylesheet>
dolmen