2016-09-22 1 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 Л.Д. нравится иметь текст не Задачи и результаты более 1000 знаков включая пробелы, и это должно быть просто вырезан после 1000 знаков

+0

Этот атрибут относится к числу символов в строке, это не имеет никакого отношения ко всему выходу. Без какой-либо идеи, что вы пытаетесь вывести, сложно предложить подходящее решение. – Flynn1179

ответ

1

Ваш вопрос не ясно, и пример особенно сбивает с толку.

Если я правильно угадываю, вы хотите постепенно конкатенировать строковые значения некоторых узлов, пока не достигнете строки определенной предопределенной длины. В следующем примере показан способ сделать это:

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, вы можете заменить рекурсивный именованный шаблон на функцию.