0
我有這樣一個XML文件,XSLT - 應用模板到子節點和文本()節點
<content>
<ol>
<li> List<span style="color: rgb(255,0,255);">The scopeeeee of</span>this project is
<ol>
<li>nested list1</li>
<li>nested <span style="color: rgb(255,0,255);">The scope of this project is</span> list1</li>
<li>nested list1</li>
<li>nested list1</li>
<li>nested list1</li>
</ol>
</li>
<li>
<p>List<span style="color: rgb(255,0,255);">The scope of this project is to:</span></p>
</li>
<li>
<p>List<span style="color: rgb(255,0,255);">The scope of this project is to:</span></p>
</li>
</ol>
</content>
我需要使用XSLT
預期產出上面的XML轉換到下面的XML,
<content>
<orderedList>
<liItem>
<para>List<c type="color: rgb(255,0,255);">The scopeeeee of this project is to:</c>jkhsdlkjfh</para>
</liItem>
<orderedList>
<liItem>
<para>nested list1</para>
</liItem>
<liItem>
<para>nested <c type="color: rgb(255,0,255);">The scope of this project is</c>list1</para>
</liItem>
<liItem>
<para>nested list1</para>
</liItem>
<liItem>
<para>nested list1</para>
</liItem>
<liItem>
<para>nested list1</para>
</liItem>
</orderedList>
<liItem>
<para> List<c type="color: rgb(255,0,255);">The scope of this project is to:</c></para>
</liItem>
<liItem>
<para> List<c type="color: rgb(255,0,255);">The scope of this project is to:</c></para>
</liItem>
</orderedList>
</content>
如您所見,li項中的文本內容和跨度節點必須在輸出中包含<para>
節點。
我已經寫了下面的XSL來得到這個輸出,
<xsl:template match="ol">
<orderedList>
<xsl:apply-templates/>
</orderedList>
</xsl:template>
<xsl:template match="li[not(descendant::ol)]" >
<liItem>
<para>
<xsl:apply-templates />
</para>
</liItem>
</xsl:template>
<xsl:template match="li[descendant::ol]" >
<liItem>
<para>
<xsl:apply-templates select="node()[parent::li][following-sibling::ol]"/>
</para>
</liItem>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="span">
<c type="{@style}">
<xsl:apply-templates/>
</c>
</xsl:template>
<xsl:template match="li/p">
<xsl:apply-templates />
</xsl:template>
以上的xsl唯一的問題是來的時候它有<ol>
內的另一個<ol>
項目。我正在努力尋找一種方法,將<para>
節點添加到位於<li>
和<ol>
節點之間的文本內容。
電流輸出如下,
<content>
<orderedList>
<liItem>
<para> List<c type="color: rgb(255,0,255);">The scopeeeee of</c>this project is</para>
</liItem> List<c type="color: rgb(255,0,255);">The scopeeeee of</c>this project is
<orderedList>
<liItem><para>nested list1</para></liItem>
<liItem><para>nested <c type="color: rgb(255,0,255);">The scope of this project is</c>list1</para></liItem>
<liItem><para>nested list1</para></liItem>
<liItem><para>nested list1</para></liItem>
<liItem><para>nested list1</para></liItem>
</orderedList>
<liItem><para> List<c type="color: rgb(255,0,255);">The scope of this project is to:</c></para></liItem>
<liItem><para> List<c type="color: rgb(255,0,255);">The scope of this project is to:</c></para></liItem>
</orderedList>
</content>
任何人都可以建議我一個辦法,我怎麼能修改我的代碼,以獲得預期輸出..