为什么使用IF-条件进行EATH选择全部而不是特定节点的属性
编辑:我找到了一个对我有用的解决方案(确实,最好更改RDF语法,如Conal Tuohy所建议的):
<xsl:variable name="all_rels_comparable" select="$all/relations/rel[@name = 'is_comparable_to']"/>
<xsl:for-each select="$all_rels_comparable[@from = $id_lexUnit]">
<bla:is_comparable_to rdf:resource="blabla/is_comparable_to/{./@to}" />
</xsl:for-each>
我正在将各种XML文件的信息整合到单个RDF-XML文件中。 当我尝试检索单个节点时,我总是用尽内存,因为它在以某种方式迭代了许多节点。行&lt; xsl:value-os select =“ $ all/resstance/rely/@to”/&gt;
是这里的问题。正确的方法是什么?
这是我的XSL脚本:
<xsl:stylesheet version="3.0">
<xsl:template match="node()|@*">
<rdf:RDF
xmlns:bla="blabla"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<xsl:variable name="all" select="collection('./?select=*.xml')"/>
<xsl:for-each select="$all/sets/singleSet/unit">
<xsl:variable name="id_unit" select="./@id"/>
<xsl:variable name="uri_unit">
<xsl:copy-of select="concat('https://blabla/', $id_unit)" />
</xsl:variable>
<NamedIndividual rdf:about="{$uri_unit}">
<bla:identifier rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
<xsl:value-of select="./@id"/>
</bla:identifier>
<!-- THIS PART DOES NOT WORK AS EXPECTED: -->
<xsl:if test="(($all/relations/rel/@name = 'is_comparable_to') and ($all/relations/rel/@from = $id_unit))">
<bla:is_comparable_to rdf:resource="blabla/is_comparable_to">
<xsl:value-of select="$all/relations/rel/@to"/>
</bla:is_comparable_to>
</xsl:if>
</NamedIndividual>
</xsl:for-each>
</rdf:RDF>
</xsl:template>
</xsl:stylesheet>
这是我尝试仅获得“ to”的最后一行值的文件:
<relations>
<rel name="has_user" from="28" to="45" dir="one" />
<rel name="is_part_of" from="22" to="90" dir="one" />
<rel name="is_comparable_to" from="55" to="36" dir="one" />
<rel name="is_comparable_to" from="11" to="40" dir="one" />
</relations>
因此,这是我打算获得的输出:
<NamedIndividual rdf:about="https://blabla/11">
<bla:identifier rdf:datatype="http://www.w3.org/2001/XMLSchema#string">11</bla:identifier>
<bla:is_comparable_to rdf:resource="blabla/is_comparable_to">40</bla:is_comparable_to>
</NamedIndividual>
EDIT: I found a solution that works for me (and it is indeed better to change the RDF syntax, as Conal Tuohy suggested):
<xsl:variable name="all_rels_comparable" select="$all/relations/rel[@name = 'is_comparable_to']"/>
<xsl:for-each select="$all_rels_comparable[@from = $id_lexUnit]">
<bla:is_comparable_to rdf:resource="blabla/is_comparable_to/{./@to}" />
</xsl:for-each>
I am consolidating information from various XML-files into a single RDF-XML file.
I always run out of memory when I try to retrieve a single node as it somehow iterates over many more nodes than intended. The line <xsl:value-of select="$all/relations/rel/@to"/>
is the problem here, I guess. What would be the correct way to do it?
This is my xsl script:
<xsl:stylesheet version="3.0">
<xsl:template match="node()|@*">
<rdf:RDF
xmlns:bla="blabla"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<xsl:variable name="all" select="collection('./?select=*.xml')"/>
<xsl:for-each select="$all/sets/singleSet/unit">
<xsl:variable name="id_unit" select="./@id"/>
<xsl:variable name="uri_unit">
<xsl:copy-of select="concat('https://blabla/', $id_unit)" />
</xsl:variable>
<NamedIndividual rdf:about="{$uri_unit}">
<bla:identifier rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
<xsl:value-of select="./@id"/>
</bla:identifier>
<!-- THIS PART DOES NOT WORK AS EXPECTED: -->
<xsl:if test="(($all/relations/rel/@name = 'is_comparable_to') and ($all/relations/rel/@from = $id_unit))">
<bla:is_comparable_to rdf:resource="blabla/is_comparable_to">
<xsl:value-of select="$all/relations/rel/@to"/>
</bla:is_comparable_to>
</xsl:if>
</NamedIndividual>
</xsl:for-each>
</rdf:RDF>
</xsl:template>
</xsl:stylesheet>
This is the file where I try to get only the last lines value of 'to':
<relations>
<rel name="has_user" from="28" to="45" dir="one" />
<rel name="is_part_of" from="22" to="90" dir="one" />
<rel name="is_comparable_to" from="55" to="36" dir="one" />
<rel name="is_comparable_to" from="11" to="40" dir="one" />
</relations>
so this is the output I intend to get:
<NamedIndividual rdf:about="https://blabla/11">
<bla:identifier rdf:datatype="http://www.w3.org/2001/XMLSchema#string">11</bla:identifier>
<bla:is_comparable_to rdf:resource="blabla/is_comparable_to">40</bla:is_comparable_to>
</NamedIndividual>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在做
,在身体内部,您有几个路径表达式,以
$ $ all/Ressection
IS
关系
单位>单位
的子元素?无论如何,从$ $ all
进行选择时,当您当前正在处理元素时,从$ $ all
处理几个级别似乎很奇怪。但是,如果不看到整体XML的外观,我们看不到如何纠正它。You're doing
and within the body you have several path expressions beginning with
$all/relations
Is
relations
a child element ofunit
perhaps? At any rate, it seems very odd to be doing a selection starting at$all
when you are currently processing elements several levels down from$all
. But without seeing what the overall XML looks like, we can't see how to correct it.在我看来,在您的
XSL中:for-east
您正在搜索关系
寻找rel
连接您当前unit的元素
到其他单位
。如果我正确理解了它,则应使用类似的东西,代替您的XSL:如果
block:但在您的示例中,RDF/XML语法表示
is_comparable_to
/代码>属性混淆。我认为也许您打算将单位(
bla:is_comparable_to
)之间的关系建模为RDF对象属性?即...屈服:
It seems to me that within your
xsl:for-each
you are searching therelations
looking forrel
elements which connect your currentunit
to some otherunit
. If I've understood it correctly, you should use something like this, in place of yourxsl:if
block:But also, in your example the RDF/XML syntax for expressing that
is_comparable_to
property is confused. I think maybe you intend to model the relationship between units (bla:is_comparable_to
) as an RDF Object Property? i.e.... yielding: