XML/XSLT stylesheet/comment

Материал из Web эксперт
Версия от 11:26, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Add comments to generated xml

   <source lang="xml">

File: Data.xml <documentation>test</documentation>

File: Transform.xslt <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

 version="1.0">
 <xsl:output method="xml" omit-xml-declaration="yes" indent="no" />
 
 <xsl:template match="poem">
   <html>
     <xsl:comment>
       Created by release 3
     </xsl:comment>
     <xsl:apply-templates />
   </html>
 </xsl:template>
 

</xsl:stylesheet> Output: test

</source>
   
  


Copy comment with comment() function

   <source lang="xml">

File: Data.xml <documentation>The following is a revision.</documentation>

File: Transform.xslt <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

 version="1.0">
 <xsl:output method="xml" omit-xml-declaration="yes" indent="no" />
 <xsl:template match="comment()">
   <xsl:comment>
     <xsl:value-of select="." />
   </xsl:comment>
 </xsl:template>
 

</xsl:stylesheet> Output: The following is a revision.

</source>
   
  


Create comment in style sheet

   <source lang="xml">

File: Data.xml <documentation>The following is a revision.</documentation> File: Transform.xslt <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

 version="1.0">
 <xsl:output method="xml" omit-xml-declaration="yes" indent="no" />
 
 <xsl:template match="documentation">
   <xsl:comment>
     <xsl:apply-templates />
   </xsl:comment>
 </xsl:template>
 

</xsl:stylesheet> Output:

</source>
   
  


Hyphens in xsl:comment element make it illegal

   <source lang="xml">

File: Data.xml <documentation>The following is a revision.</documentation> File: Transform.xslt

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

 version="1.0">
 <xsl:template match="poem">
   <html>
     <xsl:comment>
       this is the comment
     </xsl:comment>
     <xsl:apply-templates />
   </html>
 </xsl:template>

</xsl:stylesheet> Output: <?xml version="1.0" encoding="UTF-8"?>The following is a revision.

</source>
   
  


match comment

   <source lang="xml">

File: Data.xml <verse>test</verse> File: Transform.xslt <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

 version="1.0">
 <xsl:output omit-xml-declaration="yes" />
 <xsl:template match="comment()">
   <doc>
     <xsl:value-of select="." />
   </doc>
 </xsl:template>
 <xsl:template match="verse">

<xsl:apply-templates />

 </xsl:template>

</xsl:stylesheet>

Output:

test

</source>