使用xpath将xml转换为csv

时间:2016-10-21 08:35:40

标签: java xml csv xpath

我正在尝试使用带有xpath的xls将我的xml转换为csv。

这是我的xml

<name />
    <description />
    <pageModel>
        <unit>cm</unit>
        <width>19.48</width>
        <height>28.34</height>
        <inputColors>
            <inputColor b="127.315" g="61.728" r="55.061" type="blue" />
            <inputColor b="170.004" g="112.173" r="69.585" type="cyan" />
            <inputColor b="81.428" g="140.926" r="63.532" type="green" />
            <inputColor b="105.207" g="224.672" r="238.526" type="yellow" />
            <inputColor b="73.704" g="58.716" r="206.432" type="red" />
            <inputColor b="103.883" g="62.102" r="190.73" type="magenta" />
            <inputColor b="243.341" g="246.054" r="253.908" type="white" />
            <inputColor b="44.961" g="42.44" r="45.211" type="black" />
            <inputColor b="173.85" g="176.118" r="184.838" type="grey1" />
            <inputColor b="121.833" g="121.926" r="128.173" type="grey2" />
            <inputColor b="84.001" g="84.063" r="89.115" type="grey3" />
            <inputColor b="60.052" g="60.126" r="63.885" type="grey4" />
        </inputColors>
    </pageModel>
    <bibilographicMetaData>
        <idno>Hs. 1108/55 4°</idno>
        <material>Papier/Pergament</material>
        <pageDimension />
        <origDate>15. Jh.</origDate>
        <leavesCount>132 Bll.</leavesCount>
    </bibilographicMetaData>

以下是我的xls模型

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output method="text" omit-xml-declaration="yes" indent="no" />
    <xsl:template match="/">
        manuscript.name, manuscript.description,manuscript.pagemodel.unit,manuscrpt.pagemodel.width,manuscript.pagemodel.height, manuscript.inputcolor.type,manuscript.inputcolor.r, manuscript.inputcolor.g, manuscript.inputcolor.b,bibliographicmetadat.idno, manuscript.bibliographicmetadat.material, manuscript.bibliographicmetadat.origDate,manuscript.bibliographicmetadat.leavesCount
        <xsl:for-each select="//pageModel">
            <xsl:value-of
                    select="concat(name,',',description,',',unit,',',width,',',height,',',//inputColor/@type,',',//inputColor/@r,',',//inputColor/@g,',',//inputColor/@b,',','&#xD;')" />

            <xsl:for-each select="//inputColors">

                    <xsl:for-each select="//inputColor">

                <xsl:value-of
                    select="concat(name,',',description,',',unit,',',width,',',height,',',//inputColor/@type,',',//inputColor/@r,',',//inputColor/@g,',',//inputColor/@b,',','&#xD;')" />


            </xsl:for-each>


            </xsl:for-each>
        </xsl:for-each>

        <xsl:for-each select="//bibilographicMetaData">

                <xsl:value-of
                    select="concat(name,',',description,',',unit,',',width,',',height,',',//inputColor/@type,',',//inputColor/@r,',',//inputColor/@g,',',//inputColor/@b,',',idno,',',material,',',origDate,',',leavesCount,',')" />


            </xsl:for-each>


    </xsl:template>
</xsl:stylesheet>

但是当我在下面运行时输出。 enter image description here

我在哪里尝试将输出作为

enter image description here

有人可以帮我改变xls模型,以便我可以在我的csv中获得第二种风格。甚至线索也很有帮助。

三江源。

0 个答案:

没有答案