我想知道有没有人可以帮我解决以下问题。我有一个XML文件,它的文本值包含每周一个值。我想把每周作为一个单独的行放入数据库中。
我知道如何使用SSIS将XML文件放入数据库中,但我需要一些帮助来开始拆分文本值。
非常感谢!
<DATA>
<TIME-SERIES last-update-time="507340800" name="yearly" sample-interval="604800" observations="52" parent="http:client-volume">143 161 175 112 176 191 188 163 268 303 261 270 264 182 318 307 339 310 328 338 407 485 3330 274 168 191 179 258 183 256 258 238 2625 235 305 274 255 273 367 188 318 230 315 278 192 222 1268 129 150 350 3278 4757 </TIME-SERIES>
</DATA>首选输出
date | name | interval | observation | parent | value
507340800 | yearly | 604800 | 52 | http:client-volume | 143
507340800 | yearly | 604800 | 52 | http:client-volume | 161
507340800 | yearly | 604800 | 52 | http:client-volume | 175发布于 2012-02-29 20:41:09
为此编写一个小的xsl代码片段如何?这是我想出来的,运行:xsltproc MY_XSL_FILE YOUR_XML_FILE
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:s="http://exslt.org/strings"
version="1.0">
<xsl:output method="text"/>
<xsl:template match="text()"/>
<xsl:template match="TIME-SERIES">
<xsl:variable name="last-update-time" select="@last-update-time"/>
<xsl:variable name="name" select="@name"/>
<xsl:variable name="sample-interval" select="@sample-interval"/>
<xsl:variable name="observations" select="@observations"/>
<xsl:variable name="parent" select="@parent"/>
<!-- heading -->
<xsl:text>date | name | interval | observation | parent | value
</xsl:text>
<xsl:for-each select="s:tokenize(text(), ' ')">
<xsl:value-of select="$last-update-time"/>
<xsl:text> | </xsl:text>
<xsl:value-of select="$name"/>
<xsl:text> | </xsl:text>
<xsl:value-of select="$sample-interval"/>
<xsl:text> | </xsl:text>
<xsl:value-of select="$observations"/>
<xsl:text> | </xsl:text>
<xsl:value-of select="$parent"/>
<xsl:text> | </xsl:text>
<xsl:value-of select="."/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>https://stackoverflow.com/questions/9487794
复制相似问题