< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
< xsl:template name ="numbers" > < xsl:param name ="current-number" /> < xsl:param name ="max-number" /> < xsl:value-of select ="$current-number" /> <!-- --> < xsl:if test ="$current-number < $max-number" > <!-- , --> < xsl:text > </ xsl:text > <!-- --> < xsl:call-template name ="numbers" > < xsl:with-param name ="current-number" select ="$current-number + 1" /> < xsl:with-param name ="max-number" select ="$max-number" /> </ xsl:call-template > </ xsl:if > </ xsl:template > * This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- < xsl: template match = "/" >
- < xsl: call-template name = "numbers" >
- < xsl: with-param name = "current-number" select = "1" />
- < xsl: with-param name = "max-number" select = "50" />
- </ xsl: call-template >
- </ xsl: template >
* This source code was highlighted with Source Code Highlighter .
- <? xml version = "1.0" ? >
- < strings >
- < string > bla1 bla2 bla1 bla2 bla1 </ string >
- </ strings >
* This source code was highlighted with Source Code Highlighter .
- <? xml version = '1.0' ? >
- < xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" >
- <! - you can match and just string,
- then the contents of the node will be converted to text
- but if there are more nodes inside the string (for example, <br />),
- we can get an error
- Do not forget that if we are going to work with the text,
- you need to match the text,
- make your code work obvious ->
- < xsl: template match = "string / text ()" >
- < xsl: call-template name = "colorer" >
- < xsl: with-param name = "text" select = "." />
- <! - the remaining values ​​will be taken from the default values ​​->
- </ xsl: call-template >
- </ xsl: template >
- < xsl: template name = "colorer" >
- < xsl: param name = "text" />
- <! - default delimiter - space ->
- < xsl: param name = "delimeter" select = "''" />
- <! - by default the element is colored as odd ->
- < xsl: param name = "even" select = "false" />
- < xsl: variable name = "color" >
- < xsl: choose >
- < xsl: when test = "$ even" >
- < xsl: text > red </ xsl: text >
- </ xsl: when >
- < xsl: otherwise >
- < xsl: text > green </ xsl: text >
- </ xsl: otherwise >
- </ xsl: choose >
- </ xsl: variable >
- < xsl: choose >
- <! - if the line contains a separator ->
- < xsl: when test = "contains ($ text, $ delimeter)" >
- <! - then print the string before the delimiter ->
- < span class = "{$ color}" > < xsl: value-of select = "substring-before ($ text, $ delimeter)" /> </ span >
- <! - and once again call the template for the remaining line ->
- < xsl: call-template name = "colorer" >
- < xsl: with-param name = "delimeter" select = "$ delimeter" />
- < xsl: with-param name = "even" select = "not ($ even)" />
- < xsl: with-param name = "text" select = "substring-after ($ text, $ delimeter)" />
- </ xsl: call-template >
- </ xsl: when >
- < xsl: otherwise >
- < span class = "{$ color}" > < xsl: value-of select = "$ text" /> </ span >
- </ xsl: otherwise >
- </ xsl: choose >
- </ xsl: template >
- </ xsl: stylesheet >
* This source code was highlighted with Source Code Highlighter .
- <? xml version = "1.0" ? >
- < forum >
- < pages >
- < current-page number = "3" />
- < topics-per-page count = "15" />
- < topics count = "150" />
- < link href = "page.php? number =" />
- </ pages >
- < themes >
- < theme > theme1 </ theme >
- < theme > theme2 </ theme >
- < theme > theme3 </ theme >
- < theme > theme4 </ theme >
- < theme > theme5 </ theme >
- < theme > theme6 </ theme >
- < theme > theme7 </ theme >
- < theme > theme8 </ theme >
- < theme > theme9 </ theme >
- < theme > theme10 </ theme >
- < theme > theme11 </ theme >
- < theme > theme12 </ theme >
- < theme > theme13 </ theme >
- < theme > theme14 </ theme >
- < theme > theme15 </ theme >
- </ themes >
- </ forum >
* This source code was highlighted with Source Code Highlighter .
- <? xml version = "1.0" ? >
- < xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" >
- < xsl: template match = "pages" >
- < xsl: call-template name = "page-numbers" >
- < xsl: with-param name = "total-results" select = "topics / @ count" />
- < xsl: with-param name = "results-per-page" select = "topics-per-page / @ count" />
- < xsl: with-param name = "max-from-current-page" select = "3" />
- < xsl: with-param name = "current-page" select = "current-page / @ number" />
- < xsl: with-param name = "href" select = "link / @ href" />
- </ xsl: call-template >
- </ xsl: template >
- < xsl: template name = "page-numbers" >
- < xsl: param name = "total-results" />
- < xsl: param name = "results-per-page" />
- < xsl: param name = "max-from-current-page" />
- < xsl: param name = "current-page" />
- < xsl: param name = "href" />
- <! - How many pages we have ->
- < xsl: variable name = "max-page" select = "ceiling ($ total-results div $ results-per-page)" />
- <! - If there are more than one page, then print the page numbers ->
- < xsl: if test = "1 <$ max-page" >
- <! - From which page to start displaying page numbers ->
- < xsl: variable name = "from-page" >
- < xsl: choose >
- <! - If the number of the current page is greater than the maximum distance ->
- < xsl: when test = "$ current-page> $ max-from-current-page" >
- <! - This will be the first page that is deleted a specified number of pages from the current one ->
- < xsl: value-of select = "$ current-page - $ max-from-current-page" />
- </ xsl: when >
- < xsl: otherwise > 1 </ xsl: otherwise >
- </ xsl: choose >
- </ xsl: variable >
- <! - Which page to finish printing page numbers ->
- < xsl: variable name = "to-page" >
- < xsl: choose >
- <! - If the number of the current page is removed from the last page number more than the maximum distance ->
- < xsl: when test = "$ max-page - $ current-page> $ max-from-current-page" >
- <! - Then the last page will be deleted for a specified number of pages from the current one ->
- < xsl: value-of select = "$ current-page + $ max-from-current-page" />
- </ xsl: when >
- < xsl: otherwise >
- < xsl: value-of select = "$ max-page" />
- </ xsl: otherwise >
- </ xsl: choose >
- </ xsl: variable >
- <! - If the current page is not the first, then output arrows with a link to the previous page ->
- < xsl: if test = "1! = $ current-page" >
- <a href = "{$ href} {$ current-page - 1}"> <<</ a >
- < xsl: text > </ xsl: text >
- </ xsl: if >
- <! - Call the page numbering template with initial values ​​->
- < xsl: call-template name = "page-number" >
- < xsl: with-param name = "max-page-number" select = "$ to-page" />
- < xsl: with-param name = "current-number" select = "$ from-page" />
- < xsl: with-param name = "current-page" select = "$ current-page" />
- < xsl: with-param name = "href" select = "$ href" />
- </ xsl: call-template >
- <! - If the current page is not the last, then output arrows with a link to the next page ->
- < xsl: if test = "$ max-page! = $ current-page" >
- < xsl: text > </ xsl: text >
- <a href = "{$ href} {$ current-page + 1}"> >> </ a >
- </ xsl: if >
- </ xsl: if >
- </ xsl: template >
- < xsl: template name = "page-number" >
- < xsl: param name = "max-page-number" />
- < xsl: param name = "current-number" />
- < xsl: param name = "current-page" />
- < xsl: param name = "href" />
- < xsl: choose >
- <! - If we display the number of the current page, then without reference ->
- < xsl: when test = "$ current-number = $ current-page" >
- < xsl: value-of select = "$ current-number" />
- </ xsl: when >
- <! - Numbers of other pages with a link ->
- < xsl: otherwise >
- <a href = "{$ href} {$ current-number}">
- < xsl: value-of select = "$ current-number" />
- </ a >
- </ xsl: otherwise >
- </ xsl: choose >
- <! - If the current number is not the last one, then we call the template for the output of the next number ->
- < xsl: if test = "$ current-number <$ max-page-number" >
- < xsl: text > | </ xsl: text >
- < xsl: call-template name = "page-number" >
- < xsl: with-param name = "max-page-number" select = "$ max-page-number" />
- < xsl: with-param name = "current-number" select = "$ current-number + 1" />
- < xsl: with-param name = "current-page" select = "$ current-page" />
- < xsl: with-param name = "href" select = "$ href" />
- </ xsl: call-template >
- </ xsl: if >
- </ xsl: template >
- < xsl: template match = "@ * | node ()" >
- < xsl: copy >
- < xsl: apply-templates select = "@ * | node ()" />
- </ xsl: copy >
- </ xsl: template >
- </ xsl: stylesheet >
Source: https://habr.com/ru/post/47545/
All Articles