Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
643 views
in Technique[技术] by (71.8m points)

xslt - Output element in comments

I need to display HTML-element in comments (for example)

<!-- <img src="path" width="100px" height="100px"/> -->

I use this approach

<?xml version="1.0" encoding="windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="no" encoding="windows-1251"/>

    <xsl:template match="myNode">
        ...
        <xsl:comment><xsl:apply-templates select="image" /></xsl:comment>
        ...
    </xsl:template>

    <xsl:template match="image">
        <img src="{@src}" width="{@width}px" height="{@height}px" />
    </xsl:template>

</xsl:stylesheet>

As a result:

<!---->

that is the code in the element xsl:comment ignored.

How do I display an item in the comments?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It might be possible to replace

<xsl:comment><xsl:apply-templates select="image" /></xsl:comment>

with

<xsl:text disable-output-escaping="yes">&lt;!--</xsl:text>
<xsl:apply-templates select="image" />
<xsl:text disable-output-escaping="yes">--&gt;</xsl:text>

Haven't tried though.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...