XSLT选择错误的值

时间:2018-05-30 13:30:10

标签: xslt xslt-1.0

Singleton& Instance() { if (!pInstance_) { // Check for dead reference if (destroyed_) { OnDeadReference(); } else { // First call—initialize Create(); } } return pInstance_; } void Singleton::OnDeadReference() { // Obtain the shell of the destroyed singleton Create(); // Now pInstance_ points to the "ashes" of the singleton // - the raw memory that the singleton was seated in. // Create a new singleton at that address new(pInstance_) Singleton; // Queue this new object's destruction atexit(KillPhoenixSingleton); // Reset destroyed_ because we're back in business destroyed_ = false; } static void Create(); { // Task: initialize pInstance_ static Singleton theInstance; pInstance_ = &theInstance; } void Singleton::KillPhoenixSingleton() { // Make all ashes again // - call the destructor by hand. // It will set pInstance_ to zero and destroyed_ to true pInstance_->~Singleton(); } virtual ~Singleton() { pInstance_ = 0; destroyed_ = true; } Singleton* Singleton::pInstance_ = 0; bool Singleton::destroyed_ = false; 等于字符串pInstance_ = 0时,我的选择语句将返回29而不是99.

如果我删除字符串myNode的测试,则choose语句将返回99。

none

1 个答案:

答案 0 :(得分:0)

我假设您在同一父级下的XML中有多个myNode个元素。例如

<nodes>
   <myNode>none</myNode>
   <myNode>site-deploy</myNode>
</nodes>

现在,当您对myNode = 'site-deploy'形式进行测试时,实际做的是检查是否有任何名为myNode的节点具有“site-deploy”文本。换句话说,它会检查所有myNode个元素,而不仅仅是第一个元素。

你如何解决它取决于你想要达到的目标。例如,可能是这样的

<xsl:for-each select="myNode">
  <myNode>
    <xsl:choose>
      <xsl:when test=". = 'site-deploy'"><xsl:text>29</xsl:text></xsl:when>
      <xsl:when test=". = 'none'"><xsl:text>99</xsl:text></xsl:when>
      <xsl:otherwise><xsl:text>100</xsl:text></xsl:otherwise>
    </xsl:choose>
  </myNode>
</xsl:for-each>

请注意,如果您只是想查看第一个myNode,那么您会myNode[1] = 'site-deploy'