首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为嵌套节点编写XSL模板

为嵌套节点编写XSL模板
EN

Stack Overflow用户
提问于 2018-10-17 22:37:29
回答 1查看 25关注 0票数 0

我有下面的XML结构,它是一个大型XML的简化版本,我需要编写一个XSL模板来从特定的节点(维度)获取数据。

我已经有了一个XSL来完成转换。添加了一个新的节点<Dimensions>,它可以在一个节点内发生多次,如下所示。我需要从general/electronics/tv/description/Dimensions读取数据,并将其内容(div标记内容)输出到最终的HTML中。<Dimensions>也可以发生在software/version/description/Dimensions节点或任何其他节点下。

,所以我的问题是:

是否有一种通用的方法来编写一个模板,该模板可以读取<Dimensions>标记的内容并输出其内容?在编写此标记的XSL模板时,我需要一些帮助。

代码语言:javascript
复制
<catalog>
  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Greatest Hits</title>
    <artist>Dolly Parton</artist>
    <country>USA</country>
    <company>RCA</company>
    <price>9.90</price>
    <year>1982</year>
  </cd>
  <DVD>
    <title>Still got the blues</title>
    <artist>Gary Moore</artist>
    <country>UK</country>
    <company>Virgin records</company>
    <price>10.20</price>
    <year>1990</year>
  </DVD>
  <DVD>
    <title>Eros</title>
    <artist>Eros Ramazzotti</artist>
    <country>EU</country>
    <company>BMG</company>
    <price>9.90</price>
    <year>1997</year>
  </DVD>
  <general>
  	<electronics>
  		<tv>
  			<name>samsung</name>
  			<model>2.1</model>
  		</tv>
  		<tv>
  			<name>vizio</name>
  			<model>2.1</model>
  			<description>
  				<span>PurColor: Enjoy millions of shades of color, fine tuned to create an incredibly vibrant picture</span>
  				<Dimensions> <div>3.6 width</div></Dimensions>
  				<span>Enjoy subtle details hidden in the shadows of color and darkness with precise lighting that reveals a lifelike picture.</span>
  				<Dimensions><div>4.8 height<div></Dimensions>
  			</description>
  		</tv>
  	</electronics>
  </general>
  <software>
  	<version>
    	<title>Sylvias Mother</title>
    	<artist>Dr.Hook</artist>
    	<country>UK</country>
    	<company>CBS</company>
    	<price>8.10</price>
    	<year>1973</year>
    	<description>
  			<span>Electric water kettle with 1.0-liter capacity and 1500 watts of power for fast results (120V ~60Hz)</span>
  			<Dimensions> <div>5.6 width</div></Dimensions>
  			<span>cordless design allows for easy filling and serving; power base with 30-inch power cord for flexible placement, plus cord wrap for compact storage.</span>
  			<Dimensions><div>5.8 height</div></Dimensions>
  		</description>
    <version>
  </software>
 
</catalog>

EN

回答 1

Stack Overflow用户

发布于 2018-10-17 22:46:03

可以使用XPath表达式检索所需元素的节点

代码语言:javascript
复制
/catalog/general/electronics/tv/description/Dimensions
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52864549

复制
相关文章

相似问题

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