2011-06-10 36 views
1

我想將XSL模板應用於XML的一部分,並將未修改的其餘部分複製到結果XML中。使用XSL複製XML的部分而不應用模板

暫時我正在做一些工作。

<xsl:template match="yt:bold"> 
    <xsl:choose> 
     <xsl:when test="ancestor::ReportContent"> //I keep the ReportContent unchanged 
      <xsl:copy><xsl:copy-of select="@*"/> 
       <xsl:apply-templates /> 
      </xsl:copy> 
     </xsl:when> 
     <xsl:otherwise> 
     <b> 
       <xsl:apply-templates /> 
      </b> 
     </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 

但我正在爲每個模板做這個......我確信有一個更優雅的方式來做到這一點。

我試圖複製使用該模板的XML部分:

<xsl:template match="ReportContent"> 
<xsl:copy><xsl:copy-of select="@*"/><xsl:apply-templates select="???" /></xsl:copy> 
</xsl:template> 

但複製當我申請的所有其他模板...我不希望這樣。

那麼,有沒有更好的方法來做我想做的事情?

在此先感謝。

回答

2

這是你想要做的嗎?

<xsl:template match="yt:bold[not(ancestor::ReportContent)]"> 
    <b> 
    <xsl:apply-templates /> 
    </b> 
</xsl:template> 

或許

<xsl:template match="ReportContent"> 
    <xsl:copy-of select="."/> 
</xsl:template> 

+1

第二個是我在找的東西。非常感謝。我將仔細看看函數xsl:copy-of – 2011-06-10 09:46:36

+0

heys btw Dimitre Novatchev告訴我要與您聯繫(http://stackoverflow.com/questions/6288212/client-side-xslt-parsing-programs/6292747)你介意給我發一封XSelerator郵件給[email protected] – Pacerier 2011-06-11 15:56:56

+0

好吧,他確實說'也許'..不幸的是我自己並沒有使用它,所以我無法幫助你。 – Flynn1179 2011-06-12 06:08:44