xslt 2.0 파일을 통해 여러 xml 파일로 분할하려는 xml 파일이 있습니다. 어떻게해야합니까? 누군가가 단계별 절차를 도와 주실 수 있습니까? 현재 Python 2.7.6을 사용하고 있습니다. 다음 코드를 사용하려고했습니다 :초보자가 파이썬에서 XSLT 2.0을 사용하여 xml 파일을 분할하는 방법
import lxml.etree as ET
dom = ET.parse(xml_filename)
xslt = ET.parse(xsl_filename)
transform = ET.XSLT(xslt)
newdom = transform(dom)
print(ET.tostring(newdom, pretty_print=True))
그러나이 값은 없음을 반환합니다.
예 XML 파일
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<name>dataset containing bounding box labels on images</name>
<comment>created by BBTag</comment>
<tags>
<tag name="Perimeter-SVT" color="#f9e99c"/>
<tag name="Perimeter-Vivon" color="#032585"/>
<tag name="ScoreBoard-Vivon" color="#bf5786"/>
<tag name="Perimeter-StarSports" color="#12dadd"/>
</tags>
<images>
<image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0011.jpg">
<box top="505" left="327" width="56" height="29">
<label>ScoreBoard-Vivon</label>
</box>
<box top="218" left="387" width="67" height="24">
<label>Perimeter-SVT</label>
</box>
</image>
<image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0005.jpg">
<box top="254" left="159" width="64" height="23">
<label>Perimeter-Vivon</label>
</box>
<box top="255" left="225" width="61" height="20">
<label>Perimeter-Vivon</label>
</box>
<box top="254" left="285" width="63" height="23">
<label>Perimeter-Vivon</label>
</box>
<box top="253" left="357" width="58" height="24">
<label>Perimeter-Vivon</label>
</box>
<box top="254" left="424" width="56" height="25">
<label>Perimeter-Vivon</label>
</box>
<box top="256" left="484" width="65" height="23">
<label>Perimeter-Vivon</label>
</box>
<box top="507" left="326" width="58" height="26">
<label>ScoreBoard-Vivon</label>
</box>
</image>
<image file="/var/www/html/tamsports.com/resources/videos/STAR_SPORTS_2_20170812/STAR_SPORTS_2_20170812-0009.jpg">
<box top="249" left="400" width="59" height="29">
<label>Perimeter-StarSports</label>
</box>
</image>
</images>
</dataset>
XSLT 2.0 파일
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:template match="//dataset/tags">
<xsl:for-each select="./tag">
<xsl:variable name="tagName" select="@name" />
<xsl:result-document method="xml" href="{$tagName}.xml">
<dataset>
<xsl:copy-of select="/dataset/name"/>
<xsl:copy-of select="/dataset/comment"/>
<tags>
<xsl:copy-of select="/dataset/tags/tag[./@name = $tagName]"/>
</tags>
<images>
<xsl:for-each select="/dataset/images/image[./box/label/text() = $tagName]">
<image>
<xsl:copy-of select="./@file"/>
<xsl:copy-of select="./box[./label[./text() = $tagName]]"/>
</image>
</xsl:for-each>
</images>
</dataset>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
흐름을 통해 스택을 만족 자세한 내용을 추가. 고맙습니다.
모든 LXML/libxslt를 파이썬 모듈에 의해 사용에는 XSLT이 지원되지 않습니다. XSLT 2의'xsl : result-document'을 사용하려면 Saxon 9, XmlPrime, Altova와 같은 XSLT 2 프로세서가 필요합니다. –