我有一個XML看起來像這樣:XSL - 更換標籤的所有實例與另一個遞歸
<Viewbox Width="29.513" Height="57.478"
>
<Canvas>
<Canvas>
<!-- Layer 1/<Group>/<Group>/<Compound Path> -->
<Path Fill="#ffffffff" Data="F1... Z"/>
<Path StrokeThickness="0.9" Stroke="#ff59595b" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Round" Data="F1 ...698"/>
</Canvas>
</Canvas>
</Viewbox>
我的XSL是這樣的:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/" >
<DrawImage>
<xsl:for-each select="//Canvas">
<DrawingGroup><xsl:copy-of select="child::*" /></DrawingGroup>
</xsl:for-each>
<xsl:for-each select="//Path">
<GeometryDrawing>
<xsl:choose>
<xsl:when test="@Fill">
<xsl:attribute name="Brush">
<xsl:value-of select="@Fill"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="@Stroke">
<xsl:attribute name="Brush">
<xsl:value-of select="@Stroke"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:attribute name="Geometry">
<xsl:value-of select="@Data"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="not(string-length(@StrokeThickness)<1 or string-length(@StrokeStartLineCap)<1 or string-length(@StrokeEndLineCap)<1 or string-length(@StrokeLineJoin)<1)">
<Pen>
<xsl:choose>
<xsl:when test="@StrokeThickness">
<xsl:attribute name="Thickness">
<xsl:value-of select="@StrokeThickness"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="@StrokeStartLineCap">
<xsl:attribute name="StartLineCap">
<xsl:value-of select="@StrokeStartLineCap"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="@StrokeEndLineCap">
<xsl:attribute name="EndLineCap">
<xsl:value-of select="@StrokeEndLineCap"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="@StrokeLineJoin">
<xsl:attribute name="LineJoin">
<xsl:value-of select="@StrokeLineJoin"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
</Pen>
</xsl:when>
</xsl:choose>
</GeometryDrawing>
</xsl:for-each>
</DrawImage>
</xsl:template>
</xsl:stylesheet>
的東西是不正確的。我的輸出是假設看起來像下圖所示,但是取而代之,我得到了DrawingGroup之外的幾何圖形,而DrawingGroup沒有像Canvas那樣嵌套。
<?xml version="1.0" encoding="utf-8" ?>
<DrawImage>
<DrawingGroup>
<DrawingGroup>
<GeometryDrawing Brush="#ffffffff" Geometry="F1....478 Z" />
<GeometryDrawing Brush="#ff59595b" Geometry="F1...98">
<Pen Thickness="0.9" StartLineCap="Round" EndLineCap="Round" LineJoin="Round" />
</GeometryDrawing>
</DrawingGroup>
</DrawingGroup>
</DrawImage>
我希望有人能告訴我該怎麼把我的DrawingGroup元素在裏面我的XSL
Path-> GeometryDrawing轉換工作正常 - 它只是Canvas-> DrawingGroup失敗 – h607732