xslt get element value based on attribute which is referenced in another node tree

你说的曾经没有我的故事 提交于 2019-11-29 17:26:51

This should get you started:

<?xml version="1.0"?>

<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#"
  xmlns:skos="http://www.w3.org/2004/02/skos/core#"
  xmlns:ns0="http://art.uniroma2.it/ontologies/vocbench#"
>

  <xsl:template match="/">
    <xsl:for-each select="//skos:Concept/ns0:isUsedAs/@rdf:resource">
      <xsl:variable name='resource' select="."/>
      <xsl:value-of select="//skos:Concept[@rdf:about=$resource]/skos:prefLabel[@xml:lang='en']"/>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

Using keys:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
       xmlns:skosxl="http://www.w3.org/2008/05/skos-xl#"
       xmlns:skos="http://www.w3.org/2004/02/skos/core#"
       xmlns:dc="http://purl.org/dc/terms/"
       xmlns:ns0="http://art.uniroma2.it/ontologies/vocbench#"
       xmlns:void="http://rdfs.org/ns/void#">
        <xsl:output method="text" omit-xml-declaration="yes" encoding="UTF-8" indent="no" />
        <xsl:key name="concepts-by-about" match="//skos:Concept" use="@rdf:about" />

        <xsl:template match="//ns0:isUsedAs[key('concepts-by-about', @rdf:resource)]">        
    =305 \\$aisUsedBy$b<xsl:value-of select="key('concepts-by-about', @rdf:resource)/skos:prefLabel[@xml:lang='en']" />        
        </xsl:template>

        <xsl:template match="text()" />
</xsl:transform>

The key gets you quick access to a Concept using its rdf:about attribute. This template will grab any ns0:isUsedAs that has a corresponding skos:Concept based on the sepcified attributes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!