1
輸入XML分組XML屬性:用XSLT
<?xml version="1.0" encoding="UTF-8"?><svg height="3553.21" width="9358.09" viewBox="0 0 9358.09 3553.21" xmlns="http://www.w3.org/2000/svg">
<rect fill="#16202c" x="0" y="0" width="9358.09" height="3553.21"/>
\t <g transform="scale(0.7)>
\t \t <g id="0-0-0" class="classPolyline" type="twycenterline" nameObject="WW12" sizeMin="" sizeMax="">
\t \t \t <polyline fill="none" stroke="#292929" stroke-width="0.2" fill-opacity="1" points="218.36444444444453,127.61111111111109 "/>
\t \t </g>
\t \t <g id="1-0-0" class="classPolyline" type="twycenterline" nameObject="WW12" sizeMin="" sizeMax="">
\t \t \t <polyline fill="none" stroke="#292929" stroke-width="0.2" fill-opacity="1" points="462.22222222222223,127.14222222222219 "/>
\t \t </g>
\t \t <g id="2-0-0" class="classPolyline" type="twy" nameObject="WW12" sizeMin="" sizeMax="">
\t \t \t <polyline fill="none" stroke="#292929" stroke-width="0.2" fill-opacity="1" points="462.22222222222223,127.14222222222219 "/>
\t \t </g>
\t \t <g id="3-0-0" class="classPolyline" type="circle" nameObject="WW12" sizeMin="" sizeMax="">
\t \t \t <text class="classText" id="12200-0-0" type="lamp_label_only" fill="#ffffff">20L-AP2-065A</text>
\t \t </g>
\t \t <g id="4-0-0" class="classPolyline" type="circle" nameObject="WW12" sizeMin="" sizeMax="">
\t \t \t <text class="classText" id="12201-0-0" type="lamp_label_only" fill="#ffffff">WW8c-008B</text>
\t \t </g>
\t </g>
</svg>
預計產量:我曾經參與
<?xml version="1.0" encoding="UTF-8"?><svg height="3553.21" width="9358.09" viewBox="0 0 9358.09 3553.21" xmlns="http://www.w3.org/2000/svg">
<rect fill="#16202c" x="0" y="0" width="9358.09" height="3553.21"/>
<g transform="scale(0.7)>
\t <g type="twycenterline">
\t \t <g id="0-0-0" class="classPolyline" type="twycenterline" nameObject="WW12" sizeMin="" sizeMax="">
\t \t \t <polyline fill="none" stroke="#292929" stroke-width="0.2" fill-opacity="1" points="218.36444444444453,127.61111111111109 "/>
\t \t </g>
\t \t <g id="1-0-0" class="classPolyline" type="twycenterline" nameObject="WW12" sizeMin="" sizeMax="">
\t \t \t <polyline fill="none" stroke="#292929" stroke-width="0.2" fill-opacity="1" points="462.22222222222223,127.14222222222219 "/>
\t \t </g>
\t </g>
\t <g type="twy">
\t \t <g id="2-0-0" class="classPolyline" type="twy" nameObject="WW12" sizeMin="" sizeMax="">
\t \t \t <polyline fill="none" stroke="#292929" stroke-width="0.2" fill-opacity="1" points="462.22222222222223,127.14222222222219 "/>
\t \t </g>
\t </g>
\t <g type="circle">
\t \t <g id="3-0-0" class="classPolyline" type="circle" nameObject="WW12" sizeMin="" sizeMax="">
\t \t \t <text class="classText" id="12200-0-0" type="lamp_label_only" fill="#ffffff">20L-AP2-065A</text>
\t \t </g>
\t \t <g id="4-0-0" class="classPolyline" type="circle" nameObject="WW12" sizeMin="" sizeMax="">
\t \t \t <text class="classText" id="12201-0-0" type="lamp_label_only" fill="#ffffff">WW8c-008B</text>
\t \t </g>
\t </g>
</g>
</svg>
我的XSLT文件。不知道什麼是對這個
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes" method="xml" />
<xsl:key name="type1" match="g" use="@type" />
<xsl:template match="/">
<svg xmlns="http://www.w3.org/2000/svg" >
<xsl:variable name="viewWidth"><xsl:value-of select=".//@width"/></xsl:variable>
<xsl:variable name="viewHeight"><xsl:value-of select=".//@height"/></xsl:variable>
<xsl:attribute name="height"><xsl:value-of select="$viewHeight" /></xsl:attribute>
<xsl:attribute name="width"><xsl:value-of select="$viewWidth" /></xsl:attribute>
<g>
<xsl:variable name="trans"><xsl:value-of select=".//@transform"/></xsl:variable>
<xsl:attribute name="transform"><xsl:value-of select="$trans" /></xsl:attribute>
<xsl:variable name="type"><xsl:value-of select=".//@type"/></xsl:variable>
<xsl:comment>trans <xsl:copy-of select="$trans" /></xsl:comment>
<xsl:comment>type <xsl:copy-of select="$type" /></xsl:comment>
<xsl:apply-templates select="g[generate-id(.)=generate-id(key('type1',@type)[1])]"/>
</g>
</svg>
</xsl:template>
<xsl:template match="g">
<xsl:comment>template <xsl:copy-of select="template" /></xsl:comment>
<g value="{@type}">
<xsl:comment>g1111 <xsl:copy-of select="g11111" /></xsl:comment>
<xsl:for-each select="key('type1', @type)">
<xsl:comment><xsl:copy-of select="@type" /></xsl:comment>
</xsl:for-each>
</g>
</xsl:template>
</xsl:stylesheet>
去錯我已經閱讀這許多博客但不是我不能夠創建組。以下是詳細信息。 輸入需要轉換爲預期輸出的XML。下面我共享了輸入和輸出XMl和我的XSLT文件。 任何幫助,請....
感謝...它的工作。你可以建議任何鏈接或書籍,以提高我的XSLT技能。我只是一個begginer。 –
https://stackoverflow.com/questions/3511759/where-can-i-find-a-good-tutorial-on-xslt-files –
我稍微改變了我的輸出結果...你能幫我改變一下嗎?被要求得到輸出.. –