2010-09-06 95 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>