我有一個非標準html元素的XML文件,如下所示: 注意:段落已縮短。XSLT拷貝但更改值
<content>
Sacrifice. It's Mass Effect 3's major theme...
<p />
Mass Effect was about time and place; you d...
<p />
Mass Effect 3 is focused more on plot th...
<p />
<img url="me3_img1.jpg">Plenty of games feat...</img>
Like Star Wars, Mass Effect 3 is an inc...
<p />
The reapers aren't your only adver...
<p />
<img url="me3_img2.jpg">If looks could kill..</img>
The series' focus on player choice is as vi...
<p />
This intense narrative is met wi...
<p />
<img url="me3_img3.jpg">The sun is sett...</img>
These are exquis...
</content>
每個段落之間會有差距。 每張圖片都必須出現在內容中的段落之間,同時必須有一個標題,內容介於之間和 請注意,有一個網址,而不是一個src,所以這必須改變。
我目前的xslt只有copy-of和css修復了佈局,但img沒有顯示,因爲我無法將url更改爲src,並且設置了標題。
請幫忙。
更新:
<xsl:for-each select='./review/content/child::*'>
<xsl:value-of select="name()"/>
<xsl:choose>
<xsl:when test="name()='p'">
<p />
</xsl:when>
<xsl:when test="name()='img'">
<div class="reviewImage">
<img>
<xsl:attribute name="src">
<xsl:value-of select="./@url"/>
</xsl:attribute>
</img>
<xsl:value-of select="."/>
</div>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
它不outputing任何文本的()。圖片和標題現在排序。
發現解決方案:
<xsl:for-each select='./review/content/node()'>
<xsl:choose>
<xsl:when test="name()='p'">
<p />
</xsl:when>
<xsl:when test="name()='img'">
<div class="reviewImage">
<img>
<xsl:attribute name="src">
<xsl:value-of select="./@url"/>
</xsl:attribute>
</img>
<xsl:value-of select="."/>
</div>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
我將如何再拆
甚至跟蹤的每個圖像屬於 – Gerardlamo我不知道你所說的「分裂p」是什麼意思,? 'copy-of'也不會這樣做,但你可能會這樣做在模板上匹配'p'和「分割」它。 –
您不需要跟蹤圖像所屬的位置。默認情況下,'apply-templates'以文檔順序對所選節點集進行操作,這樣就會發生。 –