xslt - XSL - how to set max length of whole output text file -


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

i have tried not working

example :) let have 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 must explain how mistaken idea of denouncing pleasure , praising pain born , give complete account of system, , expound actual teachings of great explorer of truth, master-builder of human happiness. no 1 rejects, dislikes, or avoids pleasure itself, because pleasure, because not know how pursue pleasure rationally encounter consequences extremely painful. nor again there loves or pursues or desires obtain pain of itself, because pain, because circumstances occur in toil , pain can procure him great pleasure. take trivial example, of ever undertakes laborious physical exercise, except obtain advantage it? has right find fault man chooses enjoy pleasure has no annoying consequences, or 1 avoids pain 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> 

i operations like

<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> 

and have otput text not longer 1000 signs including spaces , should cuted after 1000 signs

your question not clear , example confusing.

if guessing correctly, want progressively concatenate string-values of nodes, until reach string of predefined length. following example shows method this:

xml

<root>     <item>not responsible direct, indirect, incidental or consequential damages resulting defect, error or failure perform.</item>     <item>this news release contains forward-looking statements involve risks, uncertainties , assumptions.</item>     <item>if such risks or uncertainties materialize or such assumptions prove incorrect, results of organization , consolidated subsidiaries differ materially expressed or implied such forward-looking statements , assumptions.</item>     <item>all statements other statements of historical fact statements deemed forward-looking statements, including not limited statements of plans, strategies , objectives of management future operations;</item>     <item>any statements concerning expected development, performance or market share relating products , services;</item>     <item>anticipated operational , financial results; statements of expectation or belief; , statements of assumptions underlying of foregoing.</item>     <item>risks, uncertainties , assumptions include achievement of expected results , other risks described time time in quarterly reports.</item>     <item>this organization assumes no obligation , not intend 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> 

result

begin item: not responsible direct, indirect, incidental or consequential damages resulting defect, error or failure perform. end item  begin item: news release contains forward-looking statements involve risks, uncertainties , assumptions. end item  begin item: if such r 

in example, result contains 300 characters.

if using xslt 2.0, replace recursive named template function.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -