为什么使用IF-条件进行EATH选择全部而不是特定节点的属性

发布于 2025-02-09 17:27:13 字数 2926 浏览 3 评论 0原文

编辑:我找到了一个对我有用的解决方案(确实,最好更改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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昵称有卵用 2025-02-16 17:27:13

您正在做

<xsl:for-each select="$all/sets/singleSet/unit">

,在身体内部,您有几个路径表达式,以$ $ all/Ressection

IS 关系 单位>单位的子元素?无论如何,从$ $ all进行选择时,当您当前正在处理元素时,从$ $ all处理几个级别似乎很奇怪。但是,如果不看到整体XML的外观,我们看不到如何纠正它。

You're doing

<xsl:for-each select="$all/sets/singleSet/unit">

and within the body you have several path expressions beginning with $all/relations

Is relations a child element of unit 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.

孤独患者 2025-02-16 17:27:13

在我看来,在您的XSL中:for-east您正在搜索关系寻找rel连接您当前unit的元素到其他单位。如果我正确理解了它,则应使用类似的东西,代替您的XSL:如果 block:

<xsl:for-each test="$all/relations/rel[@from = $id_unit][@name = 'is_comparable_to']">
    <bla:is_comparable_to rdf:resource="blabla/is_comparable_to">
        <xsl:value-of select="@to"/>
    </bla:is_comparable_to>
</xsl:if>

但在您的示例中,RDF/XML语法表示is_comparable_to /代码>属性混淆。我认为也许您打算将单位(bla:is_comparable_to)之间的关系建模为RDF对象属性?即

<xsl:for-each test="$all/relations/rel[@from = $id_unit][@name = 'is_comparable_to']">
    <bla:is_comparable_to rdf:resource="https://blabla/{@to}"/>
</xsl:if>

...屈服:

<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="https://blabla/40"/>
</NamedIndividual>

It seems to me that within your xsl:for-each you are searching the relations looking for rel elements which connect your current unit to some other unit. If I've understood it correctly, you should use something like this, in place of your xsl:if block:

<xsl:for-each test="$all/relations/rel[@from = $id_unit][@name = 'is_comparable_to']">
    <bla:is_comparable_to rdf:resource="blabla/is_comparable_to">
        <xsl:value-of select="@to"/>
    </bla:is_comparable_to>
</xsl:if>

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.

<xsl:for-each test="$all/relations/rel[@from = $id_unit][@name = 'is_comparable_to']">
    <bla:is_comparable_to rdf:resource="https://blabla/{@to}"/>
</xsl:if>

... yielding:

<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="https://blabla/40"/>
</NamedIndividual>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文