首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XML到HTML:输出文字子节点

XML到HTML:输出文字子节点
EN

Stack Overflow用户
提问于 2011-04-06 23:36:23
回答 1查看 213关注 0票数 2

转换此XML最有效的XSL是什么:

代码语言:javascript
复制
<matflash label="popup" btn-label="Interview Transcript">
  <flashtext><a href="/education/resources/students/video_cases/protected/ece/product/media/508_Guidance_Transcript.doc">Download Transcript</a></flashtext>
  <flashtext class="H1">Linda Rudolph - Teacher</flashtext>
  <flashtext class="H1">Little Sprouts, Methuen School</flashtext>
  <flashtext><b>Interviewer:</b> Linda, could you start by describing to me what you think the basis of a well-managed classroom is. Describe in your own words, what you think the basis of a well managed classroom is? What helps you get there?</flashtext>
  <flashtext><b>Linda:</b> I think just having a well managed classroom is just having good expectations so that for the children, that they know their limits, what is expected of them, what is just being able to tell them, "Okay, this is what we're doing today.", and then just set it up for them and then they know they can accomplish it, just not having any mixed messages for them.</flashtext>
  <flashtext><b>Linda:</b> Having a well managed classroom is just having a really good curriculum that the teacher's can follow and teach the children so that they're interested and they know exactly what's expected of them and then the management comes from them just knowing what's expected of them, just setting up classroom rules and everybody being able to follow them and knowing what's expected.</flashtext>
...
</matflash>

对于此HTML:

代码语言:javascript
复制
<div id="interview">
  <div><a href="/education/resources/students/video_cases/protected/ece/product/media/508_Guidance_Transcript.doc">Download Transcript</a></div>
  <div class="H1">Linda Rudolph - Teacher</div>
  <div class="H1">Little Sprouts, Methuen School</div>
  <div><b>Interviewer:</b> Linda, could you start by describing to me what you think the basis of a well-managed classroom is. Describe in your own words, what you think the basis of a well managed classroom is? What helps you get there?</div>
  <div><b>Linda:</b> I think just having a well managed classroom is just having good expectations so that for the children, that they know their limits, what is expected of them, what is just being able to tell them, "Okay, this is what we're doing today.", and then just set it up for them and then they know they can accomplish it, just not having any mixed messages for them.</div>
  <div><b>Linda:</b> Having a well managed classroom is just having a really good curriculum that the teacher's can follow and teach the children so that they're interested and they know exactly what's expected of them and then the management comes from them just knowing what's expected of them, just setting up classroom rules and everybody being able to follow them and knowing what's expected.</div>
...
</div>

我在使用<xsl:value-of><xsl:copy>显示flashtext的文字子节点(标记和文本)时遇到了问题。

EN

Stack Overflow用户

回答已采纳

发布于 2011-04-06 23:48:09

以下样式表:

代码语言:javascript
复制
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
        </xsl:copy>
    </xsl:template>
    <xsl:template match="matflash">
        <div id="interview">
            <xsl:apply-templates />
        </div>
    </xsl:template>
    <xsl:template match="flashtext">
        <div>
            <xsl:apply-templates select="@*|node()" />
        </div>
    </xsl:template>
</xsl:stylesheet>

应用于源文档时会生成以下结果:

代码语言:javascript
复制
<div id="interview">
    <div>
        <a href="/education/resources/students/video_cases/protected/ece/product/media/508_Guidance_Transcript.doc">Download Transcript</a>
    </div>
    <div class="H1">Linda Rudolph - Teacher</div>
    <div class="H1">Little Sprouts, Methuen School</div>
    <div>
        <b>Interviewer:</b>
        Linda, could you start by describing to me what you think the basis of
        a well-managed classroom is. Describe in your own words, what you
        think the basis of a well managed classroom is? What helps you get
        there?
    </div>
    <div>
        <b>Linda:</b>
        I think just having a well managed classroom is just having good
        expectations so that for the children, that they know their limits,
        what is expected of them, what is just being able to tell them, "Okay,
        this is what we're doing today.", and then just set it up for them and
        then they know they can accomplish it, just not having any mixed
        messages for them.
    </div>
    <div>
        <b>Linda:</b>
        Having a well managed classroom is just having a really good
        curriculum that the teacher's can follow and teach the children so
        that they're interested and they know exactly what's expected of them
        and then the management comes from them just knowing what's expected
        of them, just setting up classroom rules and everybody being able to
        follow them and knowing what's expected.
    </div>
</div>

请注意,使用标识转换来复制flashtext节点下的所有元素。这适用于您的输入,但如果您具有不想复制的matflashflashtext上方或下方的元素,则需要对其进行调整。一如既往,不同的需求会产生不同的解决方案。

编辑:在反射时,如果您只想复制flashtext下的所有内容,并具有在较大文档中仍然有效的内容,则可以使用单个copy-of替换标准身份转换模板

代码语言:javascript
复制
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="matflash">
        <div id="interview"><xsl:apply-templates /></div>
    </xsl:template>
    <xsl:template match="flashtext">
        <div><xsl:copy-of select="@*|node()" /></div>
    </xsl:template>
</xsl:stylesheet>

...which会产生相同的输出。

票数 3
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5569033

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档