2011-02-02 62 views
0

我正在使用xslt1.0。我要在節點之間採用模板寬:instrText和W:fldChar寬:fldCharType = 「結束」/>和......請幫助我..在節點之間應用模板

<w:r w:rsidRPr="00ED1487"> 
    <w:rPr> 
     <w:i/> 
     <w:color w:val="E36C0A" w:themeColor="accent6" w:themeShade="BF"/> 
    </w:rPr> 
    <w:instrText xml:space="preserve" 
    > DATE \@ "dddd, MMMM dd, yyyy" \* MERGEFORMAT </w:instrText> 
</w:r> 
<w:r w:rsidRPr="00ED1487"> 
    <w:rPr> 
     <w:i/> 
     <w:color w:val="E36C0A" w:themeColor="accent6" w:themeShade="BF"/> 
    </w:rPr> 
    <w:fldChar w:fldCharType="separate"/> 
</w:r> 
<w:r w:rsidRPr="00ED1487"> 
    <w:rPr> 
     <w:i/> 
     <w:noProof/> 
     <w:color w:val="E36C0A" w:themeColor="accent6" w:themeShade="BF"/> 
    </w:rPr> 
    <w:t>Wednesday</w:t> 
</w:r> 
<w:r> 
    <w:rPr> 
     <w:noProof/> 
    </w:rPr> 
    <w:t>, February 02, 2011</w:t> 
</w:r> 
<w:r> 
    <w:fldChar w:fldCharType="end"/> 
</w:r> 
+0

您將需要提供比這更多的細節 - 您想要將上述XML轉換爲什麼?你想在你已經突出顯示的位置插入什麼?你需要複製文件並添加額外的信息嗎? – ColinE 2011-02-02 08:24:31

回答

1

這種轉變

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:w="w:w"> 
<xsl:output omit-xml-declaration="yes" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:key name="kinBetween" match="w:r" 
    use="concat(generate-id(preceding-sibling::w:r[w:instrText][1]), 
       '+', 
       generate-id(following-sibling::w:r 
           [w:fldChar/@w:fldCharType='end']) 
      ) 
     "/> 

<xsl:template match="node()|@*"> 
    <xsl:copy> 
     <xsl:apply-templates select="node()|@*"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="/*"> 
    <t> 
    <xsl:apply-templates select= 
    "key('kinBetween', 
     concat(generate-id(w:r[w:instrText][1]), 
       '+', 
       generate-id(w:r[w:fldChar/@w:fldCharType='end'][1]) 
       ) 
     ) 
    "/> 
    </t> 
</xsl:template> 
</xsl:stylesheet> 

當在所提供的輸入施加(校正爲一個良好的XML文檔):

<t xmlns:w="w:w"> 
    <w:r w:rsidRPr="00ED1487" > 
     <w:rPr> 
      <w:i/> 
      <w:color w:val="E36C0A" w:themeColor="accent6" w:themeShade="BF"/> 
     </w:rPr> 
     <w:instrText xml:space="preserve"> DATE \@ "dddd, MMMM dd, yyyy" \* MERGEFORMAT </w:instrText> 
    </w:r> 
    <w:r w:rsidRPr="00ED1487"> 
     <w:rPr> 
      <w:i/> 
      <w:color w:val="E36C0A" w:themeColor="accent6" w:themeShade="BF"/> 
     </w:rPr> 
     <w:fldChar w:fldCharType="separate"/> 
    </w:r> 
    <w:r w:rsidRPr="00ED1487"> 
     <w:rPr> 
      <w:i/> 
      <w:noProof/> 
      <w:color w:val="E36C0A" w:themeColor="accent6" w:themeShade="BF"/> 
     </w:rPr> 
     <w:t>Wednesday</w:t> 
    </w:r> 
    <w:r> 
     <w:rPr> 
      <w:noProof/> 
     </w:rPr> 
     <w:t>, February 02, 2011</w:t> 
    </w:r> 
    <w:r> 
     <w:fldChar w:fldCharType="end"/> 
    </w:r> 
</t> 

個過程(與如已經不需要特定的加工身份模板)所要求的時間間隔內完全節點,併產生想要的,正確的結果

<t xmlns:w="w:w"> 
    <w:r w:rsidRPr="00ED1487"> 
     <w:rPr> 
     <w:i/> 
     <w:color w:val="E36C0A" w:themeColor="accent6" w:themeShade="BF"/> 
     </w:rPr> 
     <w:fldChar w:fldCharType="separate"/> 
    </w:r> 
    <w:r w:rsidRPr="00ED1487"> 
     <w:rPr> 
     <w:i/> 
     <w:noProof/> 
     <w:color w:val="E36C0A" w:themeColor="accent6" w:themeShade="BF"/> 
     </w:rPr> 
     <w:t>Wednesday</w:t> 
    </w:r> 
    <w:r> 
     <w:rPr> 
     <w:noProof/> 
     </w:rPr> 
     <w:t>, February 02, 2011</w:t> 
    </w:r> 
</t> 

說明:命名kinBetween關鍵是定義和使用以確定兩個w:r元素之間的所有w:r元素,並具有start-interval-element和end-interval-element所需的屬性。