Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 4.32 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Replace new line char with <br /> XSL
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3.  
  4. <xsl:template match="/">
  5.  
  6.     <xsl:for-each select="catalog/cd">
  7.  
  8.         <xsl:if test='contains(title,"&#xA;")'>  
  9.                 <p>Found <xsl:value-of select="title" /></p>
  10.         </xsl:if>
  11.  
  12.     </xsl:for-each>
  13.  
  14. </xsl:template>
  15. </xsl:stylesheet>
  16.        
  17. <catalog>
  18.     <cd>
  19.         <title>Empire
  20. Burlesque</title>
  21.         <artist>Bob Dylan</artist>
  22.         <country>USA</country>
  23.         <company>Columbia</company>
  24.         <price>10.90</price>
  25.         <year>1985</year>
  26.     </cd>
  27.     <cd>
  28.         <title>Hide your heart</title>
  29.         <artist>Bonnie Tyler</artist>
  30.         <country>UK</country>
  31.         <company>CBS Records</company>
  32.         <price>9.90</price>
  33.         <year>1988</year>
  34.     </cd>
  35.     <cd>
  36.         <title>Greatest Hits</title>
  37.         <artist>Dolly Parton</artist>
  38.         <country>USA</country>
  39.         <company>RCA</company>
  40.         <price>9.90</price>
  41.         <year>1982</year>
  42.     </cd>
  43. </catalog>
  44.        
  45. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  46. <xsl:output omit-xml-declaration="yes" indent="yes"/>
  47. <xsl:strip-space elements="*"/>
  48.  
  49. <xsl:template match="/">
  50.   <xsl:for-each select="catalog/cd">
  51.  
  52.   <xsl:variable name="title_clean">
  53.     <xsl:call-template name="repNL">
  54.       <xsl:with-param name="pText" select="title"/>
  55.     </xsl:call-template>
  56.   </xsl:variable>
  57.  
  58.   <p><xsl:value-of select='$title_clean' /></p>
  59.  
  60.   </xsl:for-each>
  61. </xsl:template>
  62.  
  63.  
  64. <xsl:template name="repNL">
  65.   <xsl:param name="pText" select="."/>
  66.  
  67.   <xsl:copy-of select="substring-before(concat($pText,'&#xA;'),'&#xA;')"/>
  68.  
  69.   <xsl:if test="contains($pText, '&#xA;')">
  70.   <br />
  71.   <xsl:call-template name="repNL">
  72.   <xsl:with-param name="pText" select=
  73.   "substring-after($pText, '&#xA;')"/>
  74.   </xsl:call-template>
  75.   </xsl:if>
  76. </xsl:template>
  77.  
  78. </xsl:stylesheet>
  79.        
  80. <xsl:stylesheet version="1.0"
  81.  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  82.  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  83.  <xsl:strip-space elements="*"/>
  84.  
  85.  <xsl:template match="node()|@*">
  86.   <xsl:copy>
  87.    <xsl:apply-templates select="node()|@*"/>
  88.   </xsl:copy>
  89.  </xsl:template>
  90.  
  91.  <xsl:template match="text()" name="repNL">
  92.   <xsl:param name="pText" select="."/>
  93.  
  94.   <xsl:copy-of select=
  95.   "substring-before(concat($pText,'&#xA;'),'&#xA;')"/>
  96.  
  97.   <xsl:if test="contains($pText, '&#xA;')">
  98.    <br />
  99.    <xsl:call-template name="repNL">
  100.     <xsl:with-param name="pText" select=
  101.     "substring-after($pText, '&#xA;')"/>
  102.    </xsl:call-template>
  103.   </xsl:if>
  104.  </xsl:template>
  105. </xsl:stylesheet>
  106.        
  107. <catalog>
  108.     <cd>
  109.         <title>Line1
  110.         Line2
  111.         Line3
  112.         </title>
  113.         <artist>Bob Dylan</artist>
  114.         <country>USA</country>
  115.         <company>Columbia</company>
  116.         <price>10.90</price>
  117.         <year>1985</year>
  118.     </cd>
  119.     <cd>
  120.         <title>Empire
  121.         Burlesque</title>
  122.         <artist>Bob Dylan</artist>
  123.         <country>USA</country>
  124.         <company>Columbia</company>
  125.         <price>10.90</price>
  126.         <year>1985</year>
  127.     </cd>
  128.     <cd>
  129.         <title>Hide your heart</title>
  130.         <artist>Bonnie Tyler</artist>
  131.         <country>UK</country>
  132.         <company>CBS Records</company>
  133.         <price>9.90</price>
  134.         <year>1988</year>
  135.     </cd>
  136.     <cd>
  137.         <title>Greatest Hits</title>
  138.         <artist>Dolly Parton</artist>
  139.         <country>USA</country>
  140.         <company>RCA</company>
  141.         <price>9.90</price>
  142.         <year>1982</year>
  143.     </cd>
  144. </catalog>
  145.        
  146. <catalog>
  147.    <cd>
  148.       <title>Line1<br/>     Line2<br/>      Line3<br/>      
  149.       </title>
  150.       <artist>Bob Dylan</artist>
  151.       <country>USA</country>
  152.       <company>Columbia</company>
  153.       <price>10.90</price>
  154.       <year>1985</year>
  155.    </cd>
  156.    <cd>
  157.       <title>Empire<br/>        Burlesque</title>
  158.       <artist>Bob Dylan</artist>
  159.       <country>USA</country>
  160.       <company>Columbia</company>
  161.       <price>10.90</price>
  162.       <year>1985</year>
  163.    </cd>
  164.    <cd>
  165.       <title>Hide your heart</title>
  166.       <artist>Bonnie Tyler</artist>
  167.       <country>UK</country>
  168.       <company>CBS Records</company>
  169.       <price>9.90</price>
  170.       <year>1988</year>
  171.    </cd>
  172.    <cd>
  173.       <title>Greatest Hits</title>
  174.       <artist>Dolly Parton</artist>
  175.       <country>USA</country>
  176.       <company>RCA</company>
  177.       <price>9.90</price>
  178.       <year>1982</year>
  179.    </cd>
  180. </catalog>