C#仅查询XSLT的父节点



我的xslt下方: -

<IncidentTicket ExternalSystemName="{ExternalSystemName}" Company="$Company">
<xsl:if test="{Incident-LastResolvedDate} and {Incident-LastResolvedDate} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="LastResolvedDate">
      <xsl:value-of select="{Incident-LastResolvedDate}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-ServiceType} and {Incident-ServiceType} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="ServiceType">
      <xsl:value-of select="'Incident'" />
    </xsl:attribute>
  </xsl:if>
<ExternalRelease>
<xsl:if test="incTest4 and incTest4 != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:attribute name="TestDate">
<xsl:value-of select="incTest4" />
</xsl:attribute>
</xsl:if>
</ExternalRelease>
</IncidentTicket>

我们可以看到节点内有节点<ExternalRelease>

当我查询是否存在属性名称" testDate"时,: -

var isAttributeAlreadyExists = result.Descendants().Attributes("name").Where(x => x.Value == "TestDate").Any();

这总是使我归还我,因为它将其放入externalRelease节点中。

当我查询时,我不想使用诸如externalRelease之类的子节点,我只想在intistticket中检查。

我该如何实现?

结果内容: -

<IncidentTicket ExternalSystemName="{ExternalSystemName}" Company="$Company">
  <xsl:if test="{Incident-LastResolvedDate} and {Incident-LastResolvedDate} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="LastResolvedDate">
      <xsl:value-of select="{Incident-LastResolvedDate}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-ServiceType} and {Incident-ServiceType} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="ServiceType">
      <xsl:value-of select="'Incident'" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-IncidentNumber} and {Incident-IncidentNumber} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="IncidentNumber">
      <xsl:value-of select="{Incident-IncidentNumber}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-ReportedDateTime} and {Incident-ReportedDateTime} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="ReportedDateTime">
      <xsl:value-of select="{Incident-ReportedDateTime}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-LastModifiedTime} and {Incident-LastModifiedTime} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="LastModifiedTime">
      <xsl:value-of select="{Incident-LastModifiedTime}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-Priority} and {Incident-Priority} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="Priority">
      <xsl:value-of select="{Incident-Priority}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-Status} and {Incident-Status} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="Status">
      <xsl:value-of select="{Incident-Status}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-TicketDescription} and {Incident-TicketDescription} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="TicketDescription">
      <xsl:value-of select="{Incident-TicketDescription}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-AssigneeLoginId} and {Incident-AssigneeLoginId} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="AssigneeLoginId">
      <xsl:value-of select="{Incident-AssigneeLoginId}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-DueDate} and {Incident-DueDate} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="DueDate">
      <xsl:value-of select="{Incident-DueDate}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-SupportGroupName} and {Incident-SupportGroupName} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="SupportGroupName">
      <xsl:value-of select="{Incident-SupportGroupName}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-ResolutionDescription} and {Incident-ResolutionDescription} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="ResolutionDescription">
      <xsl:value-of select="{Incident-ResolutionDescription}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-Category} and {Incident-Category} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="Category">
      <xsl:value-of select="{Incident-Category}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-ClosedDate} and {Incident-ClosedDate} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="ClosedDate">
      <xsl:value-of select="{Incident-ClosedDate}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-ReportedSource} and {Incident-ReportedSource} != 'null'" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="ReportedSource">
      <xsl:value-of select="{Incident-ReportedSource}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-CreatedBy} and {Incident-CreatedBy} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="CreatedBy">
      <xsl:value-of select="{Incident-CreatedBy}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-LongDescription} and {Incident-LongDescription} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="LongDescription">
      <xsl:value-of select="{Incident-LongDescription}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-CallerId} and {Incident-CallerId} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="CallerId">
      <xsl:value-of select="{Incident-CallerId}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-Impact} and {Incident-Impact} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="Impact">
      <xsl:value-of select="{Incident-Impact}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-Urgency} and {Incident-Urgency} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="Urgency">
      <xsl:value-of select="{Incident-Urgency}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-CorrelationId} and {Incident-CorrelationId} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="CorrelationId">
      <xsl:value-of select="{Incident-CorrelationId}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-RelatedIncidents} and {Incident-RelatedIncidents} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="RelatedIncidents">
      <xsl:value-of select="{Incident-RelatedIncidents}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-RelatedProblems} and {Incident-RelatedProblems} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="RelatedProblems">
      <xsl:value-of select="{Incident-RelatedProblems}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-RelatedTasks} and {Incident-RelatedTasks}!= ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="RelatedTasks">
      <xsl:value-of select="{Incident-RelatedTasks}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-ResponseDueDate} and {Incident-ResponseDueDate} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="ResponseDueDate">
      <xsl:value-of select="{Incident-ResponseDueDate}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-ResolutionDueDate} and {Incident-ResolutionDueDate} != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="ResolutionDueDate">
      <xsl:value-of select="{Incident-ResolutionDueDate}" />
    </xsl:attribute>
  </xsl:if>
  <xsl:if test="{Incident-ConfigurationItem} and {Incident-ConfigurationItem}!= ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:attribute name="ConfigurationItem">
      <xsl:value-of select="{Incident-ConfigurationItem}" />
    </xsl:attribute>
  </xsl:if>
                  {Incident-TestCondition}
                  {Attr-Incident}
                <ExternalRelease><xsl:if test="incTest4 and incTest4 != ''" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:attribute name="TestDate"><xsl:value-of select="incTest4" /></xsl:attribute></xsl:if></ExternalRelease></IncidentTicket>

使用Elements()代替Descendants()

最新更新