XSL count of certain elements using a key
我无法获取使用键查找的元素总数。
有
不属于概念类型的
我想通过选择一个特定的非概念
有多个
XSL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <xsl:output method="text"/> <xsl:key name ="terms" match ="rdf:Description[@rdf:type = '#Concept']" use ="hasConceptUI"/> <xsl:template match="/"> <xsl:apply-templates select="rdf:RDF/rdf:Description[@rdf:type = '#A']"/> </xsl:template> <xsl:template match ="rdf:Description[@rdf:type = '#A']"> <xsl:variable name ="test" select ="key('terms', substring(hasConcept/@rdf:resource, 2))"/> <xsl:for-each select="$test/hasTerm"> <xsl:value-of select="concat(rdf:Bag/hasTermName/text(), ' ')"/> </xsl:for-each> <xsl:value-of select="concat('Term Count: ', count($test/hasTerm), ' Position:', position(), ' ', ' ')"/> </xsl:template> <!-- Exclude Classes not matched --> <xsl:template match="rdf:Description[@rdf:type != '#A']"> </xsl:template> |
XML 示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <rdf:Description rdf:ID="M0006190" rdf:type="#Concept"> <hasConceptUI>M0006190</hasConceptUI> <hasTerm> <rdf:Bag> <hasTermUI>T011956</hasTermUI> <hasTermName>Diagnostic Imaging</hasTermName> </rdf:Bag> </hasTerm> <hasTerm> <rdf:Bag> <hasTermUI>T011955</hasTermUI> <hasTermName>Imaging, Diagnostic</hasTermName> </rdf:Bag> </hasTerm> </rdf:Description> <rdf:Description rdf:ID="D010284" rdf:type="#C"> <hasParentRecord rdf:resource="#D012480" rdf:type="#C"/> <hasConcept rdf:resource="#M0015934"/> </rdf:Description> |
这是我目前使用上述样式表的输出示例:
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 | Abdomen Abdomens Abdomen Term Count: 3 Position:1 Abdominal Muscles Abdominal Muscle Muscle, Abdominal Muscles, Abdominal Bauchmuskeln Term Count: 5 Position:2 Abducens Nerve Nerve, Abducens Sixth Cranial Nerve Cranial Nerve, Sixth Nerve, Sixth Cranial Nerves, Sixth Cranial Sixth Cranial Nerves Nerve VI (deleted terms here for brevity) Nerve VIs, Cranial Nervus abducens Hirnnerv VI VI. Hirnnerv Term Count: 23 Position:3 Abomasum Abomasums Labmagen Term Count: 3 Position:4 Acanthocytes Acanthocyte Akanthozyten Term Count: 3 Position:5 |
无论如何我可以使用我的密钥来计算文档中的所有术语,而不是现在只计算每个 rdf:Description 查找的术语(不是概念)的方式。我很感激任何帮助。
我认为,如果您想使用密钥并且至少可以使用 XSLT 2,那么您可以选择
1 2 3 4 5 6 7 8 9 10 | <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <xsl:output method="text"/> <xsl:key name ="terms" match ="rdf:Description[@rdf:type = '#Concept']" use ="hasConceptUI"/> <xsl:template match="/"> <xsl:value-of select="count(rdf:RDF/rdf:Description[@rdf:type = '#A']/key('terms', hasConcept/@rdf:resource/substring(., 2))/hasTerm)"/> </xsl:template> |