XML赢得';不显示标签内的所有标签

XML赢得';不显示标签内的所有标签,xml,xslt,Xml,Xslt,问题: 我们有一个显示大量文本的XML文档。该文本被包装在-p-tags中,所有内容都被包装在一个名为-avsnitt-的标记中。然而,只有每个-avsnitt-中的第一个-p-tag-会出现 XML代码: <seksjon> <p>3.1. Introduction</p> <avsnitt> <p>SIMULA is a general purpose programming language. It inherits the al

问题:

我们有一个显示大量文本的XML文档。该文本被包装在-p-tags中,所有内容都被包装在一个名为-avsnitt-的标记中。然而,只有每个-avsnitt-中的第一个-p-tag-会出现

XML代码:

<seksjon>
<p>3.1. Introduction</p>
<avsnitt>
<p>SIMULA is a general purpose programming language. It inherits the algorithmic properties of ALGOL 60 and introduces methods for structuring data. The main characteristic of SIMULA is that it is easily modelled towards specialized problem areas, and hence can be used as a basis for Special Application Languages.</p>

<p>In this Standard the name SIMULA is considered synonymous with SIMULA 67. Although there exists a predecessor, SIMULA I, this latter language has achieved limited use. It is recommended that the language defined in this Standard be referred to as "Standard SIMULA".</p>

<p>SIMULA includes most of the ALGOL 60 language. Wherever ALGOL is used in this Standard it relates to the STANDARD ALGOL 60 definition (ISO 1538).</p>
</avsnitt>
</seksjon>

3.1。导言

SIMULA是一种通用编程语言。它继承了ALGOL 60的算法特性,并介绍了结构化数据的方法。SIMULA的主要特点是,它很容易建模到专门的问题领域,因此可以用作特殊应用程序语言的基础

在本标准中,SIMULA的名称被视为SIMULA 67的同义词。虽然有一个前身SIMULA I,但后一种语言的使用有限。建议将本标准中定义的语言称为“标准SIMULA”

SIMULA包含了大部分ALGOL 60语言。本标准中使用ALGOL时,其与标准ALGOL 60定义(ISO 1538)相关

XSL代码:

<xsl:for-each select="kapittel/seksjon">
<h2><xsl:value-of select="p"/></h2>
<br></br>
<xsl:value-of select="avsnitt/p"/>
</xsl:for-each>




如果使用XSLT 1.0,这是正确的,因为当给定包含多个节点的节点集时,的
值将按文档顺序返回该集第一个节点的字符串值。您可能希望使用
copy of
而不是
value of
,这将把所有选定的节点复制到结果树中

<xsl:for-each select="kapittel/seksjon">
<h2><xsl:value-of select="p"/></h2>
<br></br>
<xsl:copy-of select="avsnitt/p"/>
</xsl:for-each>



这将产生像这样的输出

<h2>3.1. Introduction</h2>
<br />
<p>SIMULA is a general purpose programming language. It inherits the algorithmic properties of ALGOL 60 and introduces methods for structuring data. The main characteristic of SIMULA is that it is easily modelled towards specialized problem areas, and hence can be used as a basis for Special Application Languages.</p>
<p>In this Standard the name SIMULA is considered synonymous with SIMULA 67. Although there exists a predecessor, SIMULA I, this latter language has achieved limited use. It is recommended that the language defined in this Standard be referred to as "Standard SIMULA".</p>
<p>SIMULA includes most of the ALGOL 60 language. Wherever ALGOL is used in this Standard it relates to the STANDARD ALGOL 60 definition (ISO 1538).</p>
3.1。介绍

SIMULA是一种通用编程语言。它继承了ALGOL 60的算法特性,并介绍了结构化数据的方法。SIMULA的主要特点是,它很容易建模到专门的问题领域,因此可以用作特殊应用程序语言的基础

在本标准中,SIMULA的名称被视为SIMULA 67的同义词。虽然有一个前身SIMULA I,但后一种语言的使用有限。建议将本标准中定义的语言称为“标准SIMULA”

SIMULA包含了大部分ALGOL 60语言。本标准中使用ALGOL时,其与标准ALGOL 60定义(ISO 1538)相关


如果使用XSLT 1.0,这是正确的,因为当给定包含多个节点的节点集时,
值将按文档顺序返回该集第一个节点的字符串值。您可能希望使用
copy of
而不是
value of
,这将把所有选定的节点复制到结果树中

<xsl:for-each select="kapittel/seksjon">
<h2><xsl:value-of select="p"/></h2>
<br></br>
<xsl:copy-of select="avsnitt/p"/>
</xsl:for-each>



这将产生像这样的输出

<h2>3.1. Introduction</h2>
<br />
<p>SIMULA is a general purpose programming language. It inherits the algorithmic properties of ALGOL 60 and introduces methods for structuring data. The main characteristic of SIMULA is that it is easily modelled towards specialized problem areas, and hence can be used as a basis for Special Application Languages.</p>
<p>In this Standard the name SIMULA is considered synonymous with SIMULA 67. Although there exists a predecessor, SIMULA I, this latter language has achieved limited use. It is recommended that the language defined in this Standard be referred to as "Standard SIMULA".</p>
<p>SIMULA includes most of the ALGOL 60 language. Wherever ALGOL is used in this Standard it relates to the STANDARD ALGOL 60 definition (ISO 1538).</p>
3.1。介绍

SIMULA是一种通用编程语言。它继承了ALGOL 60的算法特性,并介绍了结构化数据的方法。SIMULA的主要特点是,它很容易建模到专门的问题领域,因此可以用作特殊应用程序语言的基础

在本标准中,SIMULA的名称被视为SIMULA 67的同义词。虽然有一个前身SIMULA I,但后一种语言的使用有限。建议将本标准中定义的语言称为“标准SIMULA”

SIMULA包含了大部分ALGOL 60语言。本标准中使用ALGOL时,其与标准ALGOL 60定义(ISO 1538)相关


前面的答案确实是最简洁的。为了完整性起见,我将提供一个详细的解决方案,在XML和样式表变得越来越复杂时经常可以找到

<xsl:template match="/parent-of-seksjons">
  <xsl:apply-templates select="seksjon"/> <!-- this was your xsl:for-each -->
</xsl:template>

<xsl:template match="seksjon">
  <xsl:apply-templates/>  <!-- basically, filter the seksjon tag from output -->
</xsl:template>

<!-- (1) matches any p tag directly beneath seksjon -->
<xsl:template match="seksjon/p">
  <!-- it's bad practice to <br/> just for whitespace -->
  <h2 style="margin-bottom: 2em"><xsl:value-of select="."/></h2>
</xsl:template>

<xsl:template match="avsnitt">
  <xsl:apply-templates/>  <!-- again, filter the tag but keep it's children -->
</xsl:template>

<!-- (2) matches any p tag directly beneath avsnitt -->
<xsl:template match="avsnitt/p">
  <xsl:copy>
    <xsl:apply-templates select="@*|*"/>
  </xsl:copy>
</xsl:template>

<!-- catch-all -->
<xsl:template match="@*|*" priority="-1">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

顺便说一句,如果可能的话,我不会使用
,而是
甚至


如果这太冗长,您可以将模板(1)和模板(2)添加到XSL中,并替换您的
,前面的答案确实是最简洁的。为了完整性起见,我将提供一个详细的解决方案,在XML和样式表变得越来越复杂时经常可以找到

<xsl:template match="/parent-of-seksjons">
  <xsl:apply-templates select="seksjon"/> <!-- this was your xsl:for-each -->
</xsl:template>

<xsl:template match="seksjon">
  <xsl:apply-templates/>  <!-- basically, filter the seksjon tag from output -->
</xsl:template>

<!-- (1) matches any p tag directly beneath seksjon -->
<xsl:template match="seksjon/p">
  <!-- it's bad practice to <br/> just for whitespace -->
  <h2 style="margin-bottom: 2em"><xsl:value-of select="."/></h2>
</xsl:template>

<xsl:template match="avsnitt">
  <xsl:apply-templates/>  <!-- again, filter the tag but keep it's children -->
</xsl:template>

<!-- (2) matches any p tag directly beneath avsnitt -->
<xsl:template match="avsnitt/p">
  <xsl:copy>
    <xsl:apply-templates select="@*|*"/>
  </xsl:copy>
</xsl:template>

<!-- catch-all -->
<xsl:template match="@*|*" priority="-1">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

顺便说一句,如果可能的话,我不会使用
,而是
甚至


如果这太冗长,您可以将模板(1)和模板(2)添加到XSL中,并替换
谢谢!工作起来很有魅力!非常感谢。工作起来很有魅力!