2010-09-06 133 views
0

我需要一些xsl轉換的幫助,我不知道如何開始它,因爲我是一個新手。xslt 1.0轉換幫助

我有這樣的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="[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> 

我想將它轉換成這樣:

​​

所以我要選擇的節點,在登錄名=「域名\ flannoo」。 任何人都可以幫我這個轉變,它必須是在XSLT 1.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="[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> 

輸出:

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

好的,非常感謝:) – 2010-09-06 14:34:01

+0

@Rise_against:你很好。 – 2010-09-06 14:47:38

0

這是Alejandro的回答。這主要是一個風格問題,但如果您必須將其集成到更復雜的樣式表中,這可能是相關的。

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