1

嗨,大家好

我想创建一个 xslt 2.0 样式表来执行以下操作:

拆分下面的 xml 元素值:

<sample>Please Move the asset as below

Asset Name: My Monitor 40 inch_123456789123
Asset Serial Number: 123456789123

Current Details:
Costcenter: 1234-123456 MY COST CENTRE
Location: 12 - 1234 - 1234 - MY COST ADDRESS,12 MY STR.,10TH FLOOR,,CITY,Country Name

Destination Details: 
Cost Center: 1234-12345 : 5678-91234 Some Place</sample>

在每 70 个字符上,然后将前 9 个结果分别分配给一个固定的、配置的新元素名称,并丢弃任何剩余的匹配项。例子:

<humpty>first 70chars</humpty>
<dumpty>second70chars</dumpty>
<sat>third70chars</sat>
etc...

我考虑过使用 tokenize 但被卡住了,因为它需要一个字符串模式来匹配。我考虑过使用子字符串,但我不确定格式。

任何建议表示赞赏!

4

1 回答 1

1

如果您知道元素名称并且只想提取 70 个字符的子字符串,那么http://www.w3.org/TR/xpath/#function-substring应该这样做:

<xsl:template match="sample">
  <humpty><xsl:value-of select="substring(., 1, 70)"/></humpty>
  <dumpty><xsl:value-of select="substring(., 71, 70)"/></dumpty>
  <sat><xsl:value-of select="substring(., 141, 70)"/></sat>
  ...
</xsl:template>
于 2013-08-02T12:04:48.030 回答