使用XSLT格式化文件 [英] File formating with XSLT
问题描述
你好,
>从源文件中,我需要用XSLT创建一个带有
的结果文件
以下约束:
来源:
<来源>
< Item> AAA< / Item> ;
< Item> BBBBBBBBBB< / Item>
< Item> CCCCCCCCC< / Item>
< Item> DDDDDDDDDDDDDD< /项目>
< Item> EEEEE< / Item>
< Item> FF< / Item>
< Item> G< / Item>
< / Source>
结果:(行长= 16的文本文件,带空格)
AAA BBBBBBBBBBB
CCCCCCCCC
DDDDDDDDDDDDD
EEEEE FF G
输出文件的每一行都是由项目文本组成的
一个空格。
如果通过在行上添加新项目文本我们有超过16
个字符然后用空格填充当前行并复制ite m
文本到新行。
我不知道是否可以在XSLT中执行此操作。
谢谢为你的帮助。
奥利维尔
1月31日14:02, " olivier.scalb ... @ algosyn.com"
< olivier.scalb ... @ algosyn.comwrote:
我不知道在XSLT中是否可以这样做。
简单易行,只需添加< xsl:output method =" text" /到你的
样式表的顶部。
http://www.w3.org/TR/xslt#section-Text-Output-Method
< blockquote>使用FXSL样式表文件:
strSplit-to-Lines.xsl
并根据您的情况适当修改它。
这个转换(刚刚修改了上面的样式表,用lineLength = 16调用了
模板):
< xsl :stylesheet version =" 2.0"
xmlns:xsl =" http://www.w3.org/1999/XSL/Transform"
xmlns:f =" http://fxsl.sf.net/"
xmlns:str-split2lines-func =" f:str-split2lines-func"
排除-result-prefixes =" f str-split2lines-func"
>
< xsl:import href =" str-foldl.xsl" />
<! - - 应用于text.xml - >
< str-split2lines-func:str-split2lines-func />
< xsl:output indent =" yes" omit-xml-declaration =" yes" />
< xsl:template match =" /">
< xsl :call-template name =" str-split-to-lines">
< xsl:with-param name =" pStr"
select =" ; concat(normalize-space(/),'''')" />
< xsl:with-param name =" pLineLength" select =" 16" />
< xsl:with-param name =" pDelimiters"选择= QUOT;
\r''" />
< / xsl:call-template>
< / xsl:template>
< xsl:template name =" str-split-to-lines">
< xsl:param name =" pStr" />
< xsl:param name =" pLineLength" select =" 60" />
< xsl:param name =" pDelimiters"选择= QUOT;
\r''" />
< xsl:variable name =" vsplit2linesFun"
select =" document('''')/ * / str-split2lines-func:* [1]" />
< xsl:variable name =" vrtfParams">
< delimiters>< xsl:value-of select ="
pDelimiters" />< / delimiters>
< lineLength>< xsl:copy-of select ="
Hello,
>From the source file, I need to create with XSLT a result file with
the following constraints:
source:
<Source>
<Item>AAA</Item>
<Item>BBBBBBBBBBB</Item>
<Item>CCCCCCCCC</Item>
<Item>DDDDDDDDDDDDDDD</Item>
<Item>EEEEE</Item>
<Item>FF</Item>
<Item>G</Item>
</Source>
result: (text file with line length = 16, with spaces)
AAA BBBBBBBBBBB
CCCCCCCCC
DDDDDDDDDDDDDDD
EEEEE FF G
Each line of the output file is composed of Item texts separated by
one space.
If by adding a new item text on the line we have more than 16
characters then pad the current line with spaces and copy the item
text to a new line.
I do not know if it is possible to do that in XSLT.
Thanks for your help.
Olivier
On 31 Jan, 14:02, "olivier.scalb...@algosyn.com"
<olivier.scalb...@algosyn.comwrote:I do not know if it is possible to do that in XSLT.Dead easy, just add <xsl:output method="text" /to the top of your
stylesheet.
http://www.w3.org/TR/xslt#section-Text-Output-Method
Use the FXSL stylesheet file:
strSplit-to-Lines.xsl
And modify it appropriately for your case.
This transformation (just modified the above stylesheet, calling the
template with lineLength=16):
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:f="http://fxsl.sf.net/"
xmlns:str-split2lines-func="f:str-split2lines-func"
exclude-result-prefixes="f str-split2lines-func"><xsl:import href="str-foldl.xsl"/>
<!-- to be applied on text.xml -->
<str-split2lines-func:str-split2lines-func/>
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:call-template name="str-split-to-lines">
<xsl:with-param name="pStr"
select="concat(normalize-space(/), '' '')"/>
<xsl:with-param name="pLineLength" select="16"/>
<xsl:with-param name="pDelimiters" select="'' ''"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="str-split-to-lines">
<xsl:param name="pStr"/>
<xsl:param name="pLineLength" select="60"/>
<xsl:param name="pDelimiters" select="'' ''"/>
<xsl:variable name="vsplit2linesFun"
select="document('''')/*/str-split2lines-func:*[1]"/>
<xsl:variable name="vrtfParams">
<delimiters><xsl:value-of select="
pDelimiters"/></delimiters>
<lineLength><xsl:copy-of select="
这篇关于使用XSLT格式化文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!