2017-08-14 80 views
0

我在尝试将xml文件转换为MS Build XslTransformationTask (https://msdn.microsoft.com/en-us//library/ff598688.aspx)的文本文件。XSLT换行符在MS中不起作用构建任务

我的问题是,我只能打印新行,如果我也将它们与其他(非空间)文本。因此,例如<xsl:text>&#10;</xsl:text>不会生成换行符,但<xsl:text>&#10;sampletext</xsl:text>会。 我尝试过其他变种,如<xsl:text>&#xd;</xsl:text><xsl:text>&#xa;</xsl:text>,结果相同。

MS建设任务:

<Target AfterTargets="Build" Name="Test"> 
<XslTransformation XslInputPath="config.xslt" XmlInputPaths="config.schema.xml" OutputPaths="out.txt" /> 
</Target> 

XSLT文档:

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

<xsl:template match="/root/properties"> 

<xsl:for-each select="./*"> 

<!--working new line character:--> 
<xsl:text>&#10;name: </xsl:text> 
<xsl:value-of select="name(.)" /> 

<!--not working:--> 
<xsl:text>&#10;</xsl:text> 

</xsl:for-each> 

</xsl:template> 

<xsl:template match="text()" /> 
</xsl:stylesheet> 

回答

0

希望这有助于

<xml> 
    <property>1</property> 
    <property>2</property> 
    <property>3</property> 
</xml> 

样品XSL

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

<xsl:template match="/"> 
    <xsl:for-each select='//property'> 
     <xsl:if test='position() > 1 '><xsl:text>&#xd;</xsl:text></xsl:if> 
     <xsl:value-of select='.'/> 
    </xsl:for-each> 
</xsl:template> 

创建

1 
2 
3