[英]xslt 1.0 transformation help
I need some help with an xsl transformation, I have no idea how to begin with it because I am a novice. 我需要有关xsl转换的帮助,因为我是新手,所以我不知道如何开始转换。
I have this xml scheme: 我有这个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>
And I want to transform it to this: 我想将其转换为:
<ns0:userInfo xmlns:ns0="http://Sharepoint.userInfo">
<ID>218</ID>
<Name>Falco Lannoo</Name>
</ns0:userInfo>
So I want to select the node where the loginname = "Domain\\flannoo". 所以我想选择登录名=“ Domain \\ flannoo”的节点。 Anyone can help me with this transformation, it has to be in XSLT 1.0 任何人都可以帮助我进行这种转换,它必须在XSLT 1.0中
thank you 谢谢
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/">
<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>
Output: 输出:
<ns0:userInfo xmlns:ns0="http://Sharepoint.userInfo">
<ID>87</ID>
<Name>Falco Lannoo</Name>
</ns0:userInfo>
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.