これは、私がここに投稿した質問に関連していますxslt get element value based on attribute that is referenced in another node tree最初に属性の値を取得しようとしていますが、取得できないようです。 xml:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<rdf:RDF 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#">
<skos:Concept rdf:about="http://aims.fao.org/aos/agrovoc/c_26321">
<skos:prefLabel xml:lang="fa">آبیس ماریزیای</skos:prefLabel>
....
<skos:prefLabel xml:lang="en">Abies mariesii</skos:prefLabel>
....
<skos:broader rdf:resource="http://aims.fao.org/aos/agrovoc/c_10"/>
</skos:Concept>
<skos:Concept rdf:about="http://aims.fao.org/skosmos/agrovoc/en/page/c_1591">
<skos:prefLabel xml:lang="ar">أشجار عيد الميلاد</skos:prefLabel>
....
<skos:prefLabel xml:lang="en">christmas trees</skos:prefLabel>
....
</skos:Concept>
....
<skos:Concept>
<ns0:isUsedAs rdf:resource="http://aims.fao.org/skosmos/agrovoc/en/page/c_7776"/>
<ns0:isUsedAs rdf:resource="http://aims.fao.org/skosmos/agrovoc/en/page/c_1591"/>
</skos:Concept>
</rdf:RDF>
</root>
次のテンプレートがあります。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
....
xmlns:void="http://rdfs.org/ns/void#">
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
<xsl:template match="root">
<xsl:for-each select="rdf:RDF">
<xsl:text>START HERE</xsl:text>
<xsl:text> </xsl:text>
<xsl:text>=LDR 00000nam 2200000Ia 4500</xsl:text>
<xsl:text> </xsl:text>
<xsl:apply-templates select="rdf:Description/skos:narrowMatch" />
<xsl:text> </xsl:text>
<xsl:apply-templates select="rdf:Description/skos:exactMatch" />
<xsl:text> </xsl:text>
<xsl:apply-templates select="skos:Concept" />
<xsl:text> </xsl:text>
<xsl:apply-templates select="skos:Concept/skos:altLabel" />
<xsl:text> </xsl:text>
<xsl:apply-templates select="skos:Concept/skos:prefLabel" />
<xsl:text> </xsl:text>
<xsl:apply-templates select="skos:Concept/ns0:isUsedAs" />
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template match="//ns0:isUsedAs">
<xsl:text>=305 \\$aisUsedAs$b</xsl:text>
<xsl:value-of select="ns0:isUsedAs[@rdf:resource]" />
</xsl:template>
</xsl:stylesheet>
既に持っているメイン テンプレートを使用して skos:Concept rdf:resource の属性の値を取得しようとしていましたが、値を出力できないようです。私も変数を使ってみました:
<xsl:variable name="ns0isUsedAsvar" select="skos:Concept/ns0:isUsedAs[@rdf:resource]"/ >
そして、その変数を呼び出します。
<xsl:template match="//ns0:isUsedAs">
<xsl:text>=305 \\$aisUsedAs$b</xsl:text>
<xsl:value-of select="$ns0isUsedAsvar" />
</xsl:template>
しかし、私はそれを機能させることができないようです。何が問題なのですか?ティア!
更新 (Eric への返信): これが私の名前空間の宣言です: そして、私はそれらすべてを宣言できたと思います。次のxsltであなたの合図に従ってください:
<xsl:template match="root">
<xsl:for-each select="rdf:RDF">
<xsl:text>START HERE</xsl:text>
<xsl:text> </xsl:text>
<xsl:text>=LDR 00000nam 2200000Ia 4500</xsl:text>
<xsl:text> </xsl:text>
<xsl:apply-templates select="skos:Concept/ns0:isUsedAs" />
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template match="ns0:isUsedAs">
<xsl:text>=305 \\$aisUsedAs$b</xsl:text>
<xsl:value-of select="@rdf:resource" />
</xsl:template>
私は代わりに以下を取得しています:
START HERE
=LDR 00000nam 2200000Ia 4500
آبیس ماریزیای大白叶冷杉Abies mariesii
これはおそらく、rdf:resource 属性を持つすべてのノード要素を取得することを意味します。
update2: 特定のファイルはここにあります: http://128.199.159.143/merged-file.xml
Update3:
私が現在使用している変換は以下にあります。この xslt にコードを追加します。
<?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#"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:skosxl="http://www.w3.org/2008/05/skos-xl#"
xmlns:marc="http://www.loc.gov/MARC21/slim"
xmlns:ns0="http://art.uniroma2.it/ontologies/vocbench#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:ns1="http://art.uniroma2.it/ontologies/vocbench#"
xmlns:void="http://rdfs.org/ns/void#">
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
<xsl:template match="root">
<xsl:for-each select="rdf:RDF">
<xsl:text>START HERE</xsl:text>
<xsl:text> </xsl:text>
<xsl:text>=LDR 00000nam 2200000Ia 4500</xsl:text>
<xsl:text> </xsl:text>
<xsl:apply-templates select="rdf:Description/skos:narrowMatch" />
<xsl:text> </xsl:text>
<xsl:apply-templates select="rdf:Description/skos:exactMatch" />
<xsl:text> </xsl:text>
<xsl:apply-templates select="skos:Concept" />
<xsl:text> </xsl:text>
<xsl:apply-templates select="skos:Concept/skos:altLabel" />
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template match="skos:narrowMatch">
<xsl:text>=300 \\$a</xsl:text><xsl:value-of select="@rdf:resource" />
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="skos:exactMatch">
<xsl:text>=300 \\$a</xsl:text><xsl:value-of select="@rdf:resource" />
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="skos:Concept[ns0:hasStatus]">
<xsl:text>=300 \\$a</xsl:text><xsl:value-of select="@rdf:about" />
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="skos:Concept">
<xsl:for-each select="skos:prefLabel|skos:Concept" />
<xsl:choose>
<xsl:when test="skos:broader">
<xsl:text>=301 \\$abroader$b</xsl:text>
<xsl:value-of select="skos:prefLabel[@xml:lang='en']" />
<xsl:text>$c</xsl:text>
<xsl:value-of select="./@rdf:about" />
<xsl:text> </xsl:text>
</xsl:when>
<xsl:when test="skos:narrower">
<xsl:text>=302 \\$anarrower$b</xsl:text>
<xsl:value-of select="skos:prefLabel[@xml:lang='en']" />
<xsl:text>$c</xsl:text>
<xsl:value-of select="./@rdf:about" />
<xsl:text> </xsl:text>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="skos:definition/skos:Description/rdf-value">
<xsl:text>=303 \\$aDefinition$b</xsl:text><xsl:value-of select="@xml:lang" />
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="skos:Concept/skos:altLabel">
<xsl:text>=304 \\$aAltLabel$b</xsl:text><xsl:value-of select="." />
<xsl:text>$c</xsl:text>
<xsl:value-of select="./@xml:lang" />
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
更新 4: 私が試した xslt は、私の質問に基づいて小さなサンプルで動作しました:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
....
xmlns:void="http://rdfs.org/ns/void#">
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
<xsl:template match="root">
<xsl:for-each select="rdf:RDF">
<xsl:text>START HERE</xsl:text>
<xsl:text> </xsl:text>
<xsl:text>=LDR 00000nam 2200000Ia 4500</xsl:text>
<xsl:text> </xsl:text>
<xsl:apply-templates select="skos:Concept/rdf:Description" />
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template match="ns0:isUsedAs">
<xsl:text>=305 \\$aisUsedAs$b</xsl:text>
<xsl:value-of select="@rdf:resource" />
</xsl:template>
</xsl:stylesheet>