2016-09-22 54 views
0
<xsl:output method="text" xmlns:saxon="http://saxon.sf.net/" saxon:line-length="1000"/> 

我已經試過類似的東西,但它不工作的最大長度XSL - 如何設置整個輸出文本文件

例如:) 讓說,我有XML

<?xml version="1.0" encoding="UTF-8"?> 
<LeveL Plan="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 


<space2000> 
<values> 
<value jak="77" rak="12"</value> 
<value jak="66" rak="345"></value> 
<value jak="-50" rak="67"></value> 
<value jak="But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?" rak="Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?">1</value> 
</values> 

</space2000> 


</LeveL> 

我會喜歡做一些操作,如

<xsl:stylesheet version="2.0" 
xmlns:fn ="http://www.w3.org/2005/xpath-functions" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

<xsl:output method="text" xmlns:saxon="http://saxon.sf.net/" saxon:line-length="1000"/> 

<xsl:template match="/"> 
<xsl:for-each select="(LeveL/space2000/values)"> 
<xsl:variable name="JJJ" select="(value/@jak"/> 
<xsl:variable name="RRR" select="(value/@rak)"/> 
<xsl:text> 
O 
</xsl:text> 
<xsl:text>LA</xsl:text> 
<xsl:value-of select="$JJJ"></xsl:value-of> 
<xsl:text> </xsl:text><xsl:text>LO</xsl:text> 
<xsl:value-of select="$RRR"></xsl:value-of> 
<xsl:text> 
O 
</xsl:text> 

<xsl:choose> 
    <xsl:when test="($JJJ gt 0)"> 
     <xsl:value-of select="$JJJ"/> 
    </xsl:when> 
    <xsl:when test="($JJJ lt 0)"> 
     <xsl:value-of select="$RRR"/> 
    </xsl:when> 
     <xsl:when test="($RRR gt 0)"> 
     <xsl:value-of select="fn:concat($JJJ,$RRR)"/> 
    </xsl:when> 
    <xsl:when test="($RRR lt 0)"> 
     <xsl:value-of select="00000000000000"/> 
    </xsl:when> 

</xsl:choose> 

</xsl:for-each> 

</xsl:template> 

</xsl:stylesheet> 

和我WOU LD喜歡有otput文字不超過1000個體徵長 包括空格,它應該在1000個徵兆

+0

該屬性是指每行的字符數,與整個輸出無關。沒有任何想法想要輸出什麼,很難提供合適的解決方案。 – Flynn1179

回答

1

你的問題不明確,例子是特別混亂只是cuted。

如果我正確猜測,您希望逐步連接某些節點的字符串值,直到您達到某個預定義長度的字符串。下面的示例示出了方法做到這一點:

XML

<root> 
    <item>Not responsible for direct, indirect, incidental or consequential damages resulting from any defect, error or failure to perform.</item> 
    <item>This news release contains forward-looking statements that involve risks, uncertainties and assumptions.</item> 
    <item>If such risks or uncertainties materialize or such assumptions prove incorrect, the results of this organization and its consolidated subsidiaries could differ materially from those expressed or implied by such forward-looking statements and assumptions.</item> 
    <item>All statements other than statements of historical fact are statements that could be deemed forward-looking statements, including but not limited to statements of the plans, strategies and objectives of management for future operations;</item> 
    <item>any statements concerning expected development, performance or market share relating to products and services;</item> 
    <item>anticipated operational and financial results; any statements of expectation or belief; and any statements of assumptions underlying any of the foregoing.</item> 
    <item>Risks, uncertainties and assumptions include the achievement of expected results and other risks that are described from time to time in quarterly reports.</item> 
    <item>This organization assumes no obligation and does not intend to update these forward-looking statements.</item> 
</root> 

XSLT 1.0

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

<xsl:template match="/root"> 
    <xsl:call-template name="get-text"> 
     <xsl:with-param name="items" select="item"/> 
    </xsl:call-template> 
</xsl:template> 

<xsl:template name="get-text"> 
    <xsl:param name="items" select="/.."/> 
    <xsl:param name="text"/> 
    <xsl:param name="max-length" select="300"/> 
    <xsl:param name="prefix">BEGIN ITEM:&#10;</xsl:param> 
    <xsl:param name="suffix">&#10;END ITEM&#10;&#10;</xsl:param> 
    <xsl:variable name="next-text"> 
     <xsl:value-of select="$text"/> 
     <xsl:value-of select="$prefix"/> 
     <xsl:value-of select="$items[1]"/> 
     <xsl:value-of select="$suffix"/> 
    </xsl:variable> 
    <xsl:choose> 
     <xsl:when test="string-length($next-text) &lt; $max-length"> 
      <!-- recursive call --> 
      <xsl:call-template name="get-text"> 
       <xsl:with-param name="items" select="$items[position() > 1]"/> 
       <xsl:with-param name="text" select="$next-text"/> 
      </xsl:call-template> 
     </xsl:when> 
     <xsl:otherwise> 
      <xsl:value-of select="substring($next-text, 1, $max-length)"/> 
     </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 

</xsl:stylesheet> 

結果

BEGIN ITEM: 
Not responsible for direct, indirect, incidental or consequential damages resulting from any defect, error or failure to perform. 
END ITEM 

BEGIN ITEM: 
This news release contains forward-looking statements that involve risks, uncertainties and assumptions. 
END ITEM 

BEGIN ITEM: 
If such r 

在本例中,結果包含300個字符。

如果使用XSLT 2.0,則可以用函數替換遞歸命名模板。