xslt 1.0转换帮助

时间:2010-09-06 14:12:39

标签: xml xslt

我需要一些xsl转换的帮助,我不知道如何开始,因为我是一个新手。

我有这个xml方案:

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

我想把它变成这个:

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

所以我想选择loginname =“Domain \ flannoo”的节点。 任何人都可以帮助我进行这种转换,它必须在XSLT 1.0中

谢谢

2 个答案:

答案 0 :(得分:1)

此样式表:

<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>

正确输入:

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

输出:

<ns0:userInfo xmlns:ns0="http://Sharepoint.userInfo">
    <ID>87</ID>
    <Name>Falco Lannoo</Name>
</ns0:userInfo>

答案 1 :(得分:0)

以下是亚历杭德罗回答的替代方案。这主要是一个样式问题,但如果你必须将它集成在一个更复杂的样式表中,这可能是相关的。

<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>