Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用xslt从xml数据创建数组数组作为csv中的一个字段时,添加逗号作为分隔符_Xml_Csv_Xslt_Delimiter_Comma - Fatal编程技术网

使用xslt从xml数据创建数组数组作为csv中的一个字段时,添加逗号作为分隔符

使用xslt从xml数据创建数组数组作为csv中的一个字段时,添加逗号作为分隔符,xml,csv,xslt,delimiter,comma,Xml,Csv,Xslt,Delimiter,Comma,我的实际数据如下: <image name="101272.dcm"> <gobject type="Right"><polyline><vertex index="0" t="0.0" x="636.0" y="1920.0" z="0.0"/><vertex index="1" t="0.0" x="604.0" y="2296.0" z="0.0"/></polyline></gobject> </i

我的实际数据如下:

<image name="101272.dcm">
<gobject type="Right"><polyline><vertex index="0" t="0.0" x="636.0" y="1920.0" z="0.0"/><vertex index="1" t="0.0" x="604.0" y="2296.0" z="0.0"/></polyline></gobject>
</image>
<image name="101280.dcm">
<gobject type="Right"><polyline><vertex index="0" t="0.0" x="1776.0" y="392.0" z="0.0"/><vertex index="1" t="0.0" x="1456.0" y="424.0" z="0.0"/></polyline></gobject>
</image>
1006780多边形图像[“[3476.01196.0,0.0],”[3436.01036.0,0.0],]
1006810多边形图像[“[3064.0744.0,0.0],”[3300.0912.0,0.0],]右侧


请帮助我消除字段数据中的双引号和最后一个逗号

如果您只能使用XSLT 2.0,那么您可以这样做

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="text" />

<xsl:template match="/">
    <xsl:text>type,data,label&#10;</xsl:text>
    <xsl:apply-templates select="//parent" />
</xsl:template>

<xsl:template match="parent">
    <xsl:value-of select="@type" />
    <xsl:text>,"[</xsl:text>
    <xsl:value-of select="child1/child2/concat('[',@x,',',@y,',',@z,']')" separator="," />
    <xsl:text>]",hard coded&#10;</xsl:text>
</xsl:template>
</xsl:stylesheet>
您应该能够将其适应新的XML

注意:要查看您实际拥有的XSLT处理器和版本,请参阅以下问题


我收到以下错误:第13行:缺少必需的属性“select”。在第-->行。你能告诉我为什么吗?你能编辑我的XSLT来删除结果数据中的引号吗?上面是我创建的示例数据,因为我无法添加实际数据和需求。如果我们可以删除提取数据中的双引号,这将对我有很大帮助。我坚持了一个星期,现在我发布了我的实际数据和完整的代码。请建议请避免在回答问题后对其进行重大更改。首先,你需要确保你的问题真正代表了你的实际问题。然而,我已经用最后的建议编辑了我的答案。
seriesUID   annotationType  coordSys    data    name    label
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="text" />

<xsl:template match="/">
    <xsl:text>type,data,label&#10;</xsl:text>
    <xsl:apply-templates select="//parent" />
</xsl:template>

<xsl:template match="parent">
    <xsl:value-of select="@type" />
    <xsl:text>,"[</xsl:text>
    <xsl:value-of select="child1/child2/concat('[',@x,',',@y,',',@z,']')" separator="," />
    <xsl:text>]",hard coded&#10;</xsl:text>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="text" />

<xsl:template match="/">
    <xsl:text>type,data,label&#10;</xsl:text>
    <xsl:apply-templates select="//parent" />
</xsl:template>

<xsl:template match="parent">
    <xsl:value-of select="@type" />
    <xsl:text>,"[</xsl:text>
    <xsl:for-each select="child1/child2">
        <xsl:if test="position() > 1">,</xsl:if>
        <xsl:value-of select="concat('[',@x,',',@y,',',@z,']')" />        
    </xsl:for-each>
    <xsl:text>]",hard coded&#10;</xsl:text>
</xsl:template>

</xsl:stylesheet>