2016-03-17 79 views
0

我有一本書的xml文件,它包含多個章節標籤和多個文章標題標籤。而且我需要用相應的章節標題來獲取每篇文章標籤值的值。xslt:從書中獲取價值xml

我的XML看起來是這樣的:

<root> 
<article> 
<series-title content-type="section-heading">Reviews</series-title> 
</article> 
<title> 
<article-title>Post-epilepsy stroke: A review</article-title> 
</title> 
</root> 
<root> 
<article> 
<series-title content-type="section-heading">Original Research</series-title> 
</article> 
<title> 
<article-title>Prognostic implications of the Ankle Brachial Index</article-title> 
</title> 
</root> 
<root> 
<article> 
<series-title content-type="section-heading">Editorial</series-title> 
</article> 
<title> 
<article-title>What is NODDI and what is its role</article-title> 
</title> 
</root> 
<root> 
<article> 
<series-title content-type="section-heading">Reviews</series-title> 
</article> 
<title> 
<article-title>An update on the comorbidity of ADHD and ASD</article-title> 
</title> 
</root> 
<root> 
<article> 
<series-title content-type="section-heading">Editorial</series-title> 
</article> 
<title> 
<article-title>Occipital nerve stimulation and beyond</article-title> 
</title> 
</root> 

而且我的輸出應該是:

<h2>Reviews</h2> 
<h3>Post-epilepsy stroke: A review</h3> 
<h2>Original Research</h2> 
<h3>Prognostic implications of the Ankle Brachial Index</h3> 
<h2>Editorial</h2> 
<h3>What is NODDI and what is its role</h3> 
<h2>Reviews</h2> 
<h3>An update on the comorbidity of ADHD and ASD</h3> 
<h2>Editorial</h2> 
<h3>Occipital nerve stimulation and beyond</h3> 

而且事情是,我只用一個模板匹配條件。

任何人都可以幫助:

回答

0

這是你想要的嗎?

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="html" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/> 
<xsl:template match="/this/root"> 
    <h2> 
     <xsl:value-of select="article/series-title"/> 
    </h2> 
    <h3> 
     <xsl:value-of select="title/article-title"/> 
    </h3>  
</xsl:template> 
</xsl:stylesheet> 

,並在此解決方案,您的所有根標籤應在「這個」標籤。