2017-04-18 85 views
0

我是新来的XSLT,我试图改变以下XML:简单的XSLT转换时XML元素具有文本节点和子节点

<li>Hi there <person>David</person> , how is it going? </li> 

我想这就像转换到另一个XML的东西:

<response>Hi there PERSON_NAME , how is it going? </response> 

我到目前为止是这样的:

<xsl:template match="li"> 
    <response><xsl:value-of select="text()"/> 
    <xsl:choose> 
      <xsl:when test="person"> 
       <xsl:text> PERSON_NAME </xsl:text> 
      </xsl:when> 
    </xsl:choose> 
    </response> 
</xsl:template> 

这是输出我得到:

<response>Hi there , how is it going? PERSON_NAME</response> 

不完全是我想要的。我是xslt的新手,并读过一本书。我没有找到任何有xml元素在其文本值之间有一个子节点的情况。不知道xslt是否可以处理这个问题,或者我缺少一些基本的东西。任何帮助将不胜感激。我正在使用xslt 2.0

回答

0

您可以简单地定义两个模板来处理您的情况。

<xsl:template match="li"> 
    <response> 
     <xsl:apply-templates/> 
    </response> 
</xsl:template> 

<xsl:template match="person"> 
    <xsl:text>PERSON_NAME</xsl:text> 
</xsl:template>