2013-08-02 28 views
1

XSLT - 在每一個第n個字符分割字符串傢伙

我想創建一個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... 

我考慮過使用標記大小但被卡住了,因爲它需要一個字符串模式來匹配。我想過使用子字符串,但我不確定格式。

任何意見是讚賞!

+0

你可以用'分析,string'。不過,我不知道在哪裏,你想從 –

+0

感謝馬丁得到像'humpty'新的元素名稱。新的元素名稱將在樣式表中預先配置並始終保持不變。爲了舉例,我使用了「矮胖」等。 – Scrat

回答

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> 
相關問題