My favorites
▼
|
Sign in
lindenb
Pierre Lindenbaum's library
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
src
/
xsl
/
pubmed2fx01.xsl
r508
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:h="http://www.w3.org/1999/xhtml"
>
<!--
Motivation:
transforms a Pubmed xml result to Java FX.
Creates two charts:
number of publications/year
number of publication/journal
Author
Pierre Lindenbaum PhD plindenbaum@yahoo.fr
http://plindenbaum.blogspot.com
-->
<xsl:key name="articlesIds" match="/PubmedArticleSet/PubmedArticle/MedlineCitation/MedlineJournalInfo/NlmUniqueID" use="."/>
<!-- ========================================================================= -->
<xsl:output method='text' indent='yes' omit-xml-declaration="no"/>
<xsl:variable name="minMedlineTA">
<xsl:for-each select="/PubmedArticleSet/PubmedArticle/MedlineCitation/MedlineJournalInfo/MedlineTA">
<xsl:sort select="." order="ascending" />
<xsl:if test="position() = 1">
<xsl:value-of select="." />
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="minYear">
<xsl:for-each select="/PubmedArticleSet/PubmedArticle/MedlineCitation/DateCreated/Year">
<xsl:sort select="." data-type="number" order="ascending" />
<xsl:if test="position() = 1">
<xsl:value-of select="." />
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="maxYear">
<xsl:for-each select="/PubmedArticleSet/PubmedArticle/MedlineCitation/DateCreated/Year">
<xsl:sort select="." data-type="number" order="descending" />
<xsl:if test="position() = 1">
<xsl:value-of select="." />
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:template match="/">
import javafx.stage.Stage;
import javafx.scene.layout.LayoutInfo;
import javafx.stage.Alert;
import javafx.scene.Scene;
import javafx.scene.chart.PieChart;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.PieChart3D;
import javafx.scene.text.Font;
import javafx.scene.chart.part.CategoryAxis;
import javafx.scene.chart.part.NumberAxis;
<xsl:apply-templates select="PubmedArticleSet"/>
</xsl:template>
<xsl:template match="PubmedArticleSet">
def valuesPerYear = [
<xsl:call-template name="barPerYear"><xsl:with-param name="year" select="$minYear"/></xsl:call-template>
];
Stage {
title: "By Year"
scene: Scene {
height: 800
width: 1000
content: BarChart {
title : "Per Year"
layoutInfo: LayoutInfo {width: 580}
height: 800
width: 1000
categoryAxis: CategoryAxis { categories: for (value in valuesPerYear) value.category}
valueAxis: NumberAxis { lowerBound: 0; upperBound: <xsl:call-template name="maxPerYear"><xsl:with-param name="year" select="$minYear"/><xsl:with-param name="max" select="0"/></xsl:call-template> ; tickUnit: 10 }
data: [ BarChart.Series {
name: "Year"
data:valuesPerYear
}
]
}
}
}
Stage {
title: "By Journal"
scene: Scene {
height: 800
width: 1000
content: PieChart {
title: "By Journal"
height: 800
width: 1000
pieToLabelLineCurved: true
pieLabelFont: Font{ size:9 }
data: [
<xsl:for-each select="PubmedArticle">
<xsl:sort select="MedlineCitation/MedlineJournalInfo/MedlineTA" order="ascending" />
<xsl:if test="generate-id(MedlineCitation/MedlineJournalInfo/NlmUniqueID) = generate-id(key('articlesIds', MedlineCitation/MedlineJournalInfo/NlmUniqueID))">
<xsl:variable name="journalId" ><xsl:value-of select="MedlineCitation/MedlineJournalInfo/NlmUniqueID"/></xsl:variable>
<xsl:variable name="journalName" ><xsl:value-of select="MedlineCitation/MedlineJournalInfo/MedlineTA"/></xsl:variable>
<xsl:if test="$journalName != $minMedlineTA">,</xsl:if>
PieChart.Data {
value: <xsl:value-of select="count(/PubmedArticleSet/PubmedArticle[MedlineCitation/MedlineJournalInfo/NlmUniqueID = $journalId])"/>;
label: "<xsl:value-of select="$journalName"/>";
}
</xsl:if>
</xsl:for-each>
]
}
}
}
</xsl:template>
<xsl:template name="barPerYear">
<xsl:param name="year"/>
<xsl:if test="$year <= $maxYear">
<xsl:if test="$year != $minYear">,</xsl:if>
BarChart.Data {
category: "<xsl:value-of select="$year"/>"
value: <xsl:value-of select="count(/PubmedArticleSet/PubmedArticle[number(MedlineCitation/DateCreated/Year) = $year] )"/>
}
<xsl:call-template name="barPerYear"><xsl:with-param name="year" select="1 + $year"/></xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="maxPerYear">
<xsl:param name="year"/>
<xsl:param name="max"/>
<xsl:choose>
<xsl:when test="$year <= $maxYear">
<xsl:variable name="total" select="count(/PubmedArticleSet/PubmedArticle[number(MedlineCitation/DateCreated/Year) = $year] )"/>
<xsl:call-template name="maxPerYear">
<xsl:with-param name="year" select="1 + $year"/>
<xsl:with-param name="max">
<xsl:choose>
<xsl:when test="$total < number($max)"><xsl:value-of select="$max"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$total"/></xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number($max)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Show details
Hide details
Change log
r304
by plindenbaum on Jun 9, 2009
Diff
pubmed2fx
Go to:
/trunk/src/xsl/pubmed2fx01.xsl
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 5263 bytes, 175 lines
View raw file
Powered by
Google Project Hosting