2012-03-29 2 views
0

XML 결과를 생성하는 데 효과가있는 다음 XSLT가 있습니다. 이제는 CSV 결과를 설정하기 위해 약간 수정해야합니다. 어떤 제안.간단한 XSLT 수정 XML to CSV

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:key name="mon" match="Column[substring(@name, 4, 1) = '_']"  use="concat(parent::*/@rowNum, substring(@name, 1, 3))"/> 
<xsl:output indent="yes"/> 
<xsl:template match="node()"> 
    <xsl:copy> 
     <xsl:copy-of select="@*"/> 
     <xsl:apply-templates select="node()"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="DataSet"> 
    <xsl:copy> 
     <xsl:copy-of select="@*"/> 
     <xsl:for-each select="*/Column[generate-id() = generate-id(key('mon', concat(parent::*/@rowNum, substring(@name, 1, 3)))[1])]"> 
      <xsl:element name="{name(parent::*)}"> 
       <xsl:attribute name="rowNum"> 
        <xsl:value-of select="position()"/> 
       </xsl:attribute> 
       <xsl:attribute name="mon"> 
        <xsl:value-of select="@name"/> 
       </xsl:attribute> 
       <xsl:copy-of select="parent::*/Column[not(substring(@name, 4, 1) = '_')]"/> 
       <xsl:copy-of select="key('mon', concat(parent::*/@rowNum, substring(@name, 1, 3)))"/> 
      </xsl:element> 
     </xsl:for-each> 
    </xsl:copy> 
</xsl:template> 

답변

1

소스 파일에 대한 정보를 가지고 있지, 이것은 단지 추측 할 수 있지만,이 같은 뭔가 수 있습니다

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:key name="mon" match="Column[substring(@name, 4, 1) = '_']"  use="concat(parent::*/@rowNum, substring(@name, 1, 3))"/> 
<xsl:output method="text"/> 

<xsl:template match="DataSet/*"> 
    <xsl:text>&#10;</xsl:text> 
</xsl:template> 

<xsl:template match="DataSet"> 
<xsl:for-each select="*/Column[generate-id() = generate-id(key('mon', concat(parent::*/@rowNum, substring(@name, 1, 3)))[1])]"> 
    <xsl:value-of select="name(parent::*)"/> 
    <xsl:text>, </xsl:text> 
    <xsl:value-of select="position()"/> 
    <xsl:text>, </xsl:text> 
    <xsl:value-of select="@name"/> 
    <xsl:text>, </xsl:text> 
    <xsl:value-of select="parent::*/Column[not(substring(@name, 4, 1) = '_')]"/> 
    <xsl:text>, </xsl:text> 
    <xsl:value-of select="key('mon', concat(parent::*/@rowNum, substring(@name, 1, 3)))"/> 
</xsl:for-each> 
</xsl:template> 
</xsl:stylesheet>