XSLT 转换取决于父项值
XSLT transformation depending on parent items value
我正在努力让后续工作。
XML:
<Results xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<Result ID="4,New">
<ErrorCode>0x00000000</ErrorCode>
<ID />
<z:row ows_ContentTypeId="0x0100142A0297E606694EA802A784F2232A63" ows_Title="APT.2342362" ows_LinkTitleNoMenu="APT.2342362" ows_LinkTitle="APT.2342362" ows_LinkTitle2="APT.2342362" ows_FacilityNumber="2342362" ows_Status="New" ows_TenantArea="17;#Africa & Asia Pacific" xmlns:z="#RowsetSchema" />
</Result>
<Result ID="5,New">
<ErrorCode>0x00000000</ErrorCode>
<ID />
<z:row ows_ContentTypeId="0x0100142A0297E606694EA802A784F2232A63" ows_Title="APT.2342342" ows_LinkTitleNoMenu="APT.2342342" ows_LinkTitle="APT.2342342" ows_LinkTitle2="APT.2342342" ows_FacilityNumber="2342342" ows_Status="New" ows_TenantArea="17;#Africa & Asia Pacific" xmlns:z="#RowsetSchema" />
</Result>
我的 XSL 看起来像这样:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="/" name="ShowVariables">
<xsl:for-each select="//*[name()='z:row']">
<xsl:value-of select="@ows_Title"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我需要检查 "ErrorCode" 值是否为“0x00000000”,并根据该条件单独处理行。
使用父级选择器..
检查父级。请记住将正确的命名空间添加到样式表。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:soap="http://schemas.microsoft.com/sharepoint/soap/">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="/" name="ShowVariables">
<xsl:for-each select="//*[name()='z:row']">
<xsl:choose>
<xsl:when test="../soap:ErrorCode = '0x00000000'">
ErrorCode reached
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@ows_Title"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
另一种在 ErrorCode 上设置条件的方法是创建单独的模板。
</p>
<pre><code><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:z="#RowsetSchema" xmlns:soap="http://schemas.microsoft.com/sharepoint/soap/" version="1.0">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="/">
<xsl:apply-templates select="//soap:Result"/>
</xsl:template>
<xsl:template match="soap:Result[soap:ErrorCode = '0x00000000']">
Error detected
</xsl:template>
<xsl:template match="soap:Result[soap:ErrorCode != '0x00000000']">
<xsl:value-of select="z:row/@ows_Title"/>
</xsl:template>
</xsl:stylesheet>
我正在努力让后续工作。
XML:
<Results xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<Result ID="4,New">
<ErrorCode>0x00000000</ErrorCode>
<ID />
<z:row ows_ContentTypeId="0x0100142A0297E606694EA802A784F2232A63" ows_Title="APT.2342362" ows_LinkTitleNoMenu="APT.2342362" ows_LinkTitle="APT.2342362" ows_LinkTitle2="APT.2342362" ows_FacilityNumber="2342362" ows_Status="New" ows_TenantArea="17;#Africa & Asia Pacific" xmlns:z="#RowsetSchema" />
</Result>
<Result ID="5,New">
<ErrorCode>0x00000000</ErrorCode>
<ID />
<z:row ows_ContentTypeId="0x0100142A0297E606694EA802A784F2232A63" ows_Title="APT.2342342" ows_LinkTitleNoMenu="APT.2342342" ows_LinkTitle="APT.2342342" ows_LinkTitle2="APT.2342342" ows_FacilityNumber="2342342" ows_Status="New" ows_TenantArea="17;#Africa & Asia Pacific" xmlns:z="#RowsetSchema" />
</Result>
我的 XSL 看起来像这样:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="/" name="ShowVariables">
<xsl:for-each select="//*[name()='z:row']">
<xsl:value-of select="@ows_Title"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我需要检查 "ErrorCode" 值是否为“0x00000000”,并根据该条件单独处理行。
使用父级选择器..
检查父级。请记住将正确的命名空间添加到样式表。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:soap="http://schemas.microsoft.com/sharepoint/soap/">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="/" name="ShowVariables">
<xsl:for-each select="//*[name()='z:row']">
<xsl:choose>
<xsl:when test="../soap:ErrorCode = '0x00000000'">
ErrorCode reached
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@ows_Title"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
另一种在 ErrorCode 上设置条件的方法是创建单独的模板。
</p>
<pre><code><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:z="#RowsetSchema" xmlns:soap="http://schemas.microsoft.com/sharepoint/soap/" version="1.0">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="/">
<xsl:apply-templates select="//soap:Result"/>
</xsl:template>
<xsl:template match="soap:Result[soap:ErrorCode = '0x00000000']">
Error detected
</xsl:template>
<xsl:template match="soap:Result[soap:ErrorCode != '0x00000000']">
<xsl:value-of select="z:row/@ows_Title"/>
</xsl:template>
</xsl:stylesheet>