我试图编辑XForms中的RDF/XML(eXist-db中的XSLTForms实现),并且我需要对xf:repeat
结构中具有相同名称的元素执行不同的值约束。例如,我有一个bf:subject
元素,它可以将默认URI作为其@rdf:resource
属性的值,也可以是任意URI,链接到表单中定义的其他资源(为了简洁起见,我已经从提供的示例中省略了这些元素下面)。XForms repeat:相同的元素名称,不同的值约束
在xf:repeat
结构中,如何区分具有相同名称的元素?我可以用一个谓词来处理第一个场景,该谓词将@rdf:resource
的值限制为在xf:model
中指定的默认URI,但是我无法找到一种方法来在@rdf:resource
可以采用任意URI的情况下实现差异处理。
注意:在第二个嵌套xf:repeat中没有表单控件,因为@rdf:resource的值是使用更新XForms实例的单独JavaScript库(jsPlumb)动态更新的。
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://localhost:8080/exist/apps/xsltforms/xsltforms.xsl" type="text/xsl"?>
<?xsltforms-options debug="yes"?>
<?css-conversion no?>
<?xml-model href="http://www.oxygenxml.com/1999/xhtml/xhtml-xforms.nvdl" schematypens="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:bf="http://bibframe.org/vocab/"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Editor</title>
<!--Model-->
<xf:model id="rdf-model">
<xf:instance id="graph">
<rdf:RDF>
<bf:Work rdf:about="">
<bf:subject rdf:resource="http://id.loc.gov/vocabulary/geographicAreas/s-ag"></bf:subject>
<bf:subject rdf:resource=""/>
</bf:Work>
</rdf:RDF>
</xf:instance>
<!-- Template -->
<xf:instance id="bf-Work-template">
<rdf:RDF>
<bf:Work rdf:about="">
<bf:subject rdf:resource="http://id.loc.gov/vocabulary/geographicAreas/s-ag"></bf:subject>
<bf:subject rdf:resource=""/>
</bf:Work>
</rdf:RDF>
</xf:instance>
</xf:model>
</head>
<body>
<div id="header">
<h1>Editor</h1>
</div>
<div id="forms">
<!-- Repeat for Work entity -->
<xf:repeat nodeset="instance('graph')/bf:Work" id="repeat-Work-graph">
<!-- Repeat bf:subject elements that have a default value. -->
<xf:repeat
nodeset="bf:subject[@rdf:resource[. = 'http://id.loc.gov/vocabulary/geographicAreas/s-ag']]">
<div style="border:solid black 1px;">
<xf:input
ref="@rdf:resource[. = 'http://id.loc.gov/vocabulary/geographicAreas/s-ag']">
<xf:label>Subject</xf:label>
</xf:input>
<!-- Add new bf:subject elements that have a default value -->
<xf:trigger ref=".">
<xf:label>+</xf:label>
<xf:action ev:event="DOMActivate">
<xf:insert
nodeset="../bf:subject[@rdf:resource[. = 'http://id.loc.gov/vocabulary/geographicAreas/s-ag']]"
origin="instance('bf-Work-template')/bf:subject[@rdf:resource[. = 'http://id.loc.gov/vocabulary/geographicAreas/s-ag']]"
at="last()" position="after"></xf:insert>
</xf:action>
</xf:trigger>
<!-- Delete bf:subject elements that have a default value -->
<xf:trigger
ref=".[count(../bf:subject[@rdf:resource[. = 'http://id.loc.gov/vocabulary/geographicAreas/s-ag']]) > 1]">
<xf:label>-</xf:label>
<xf:delete ev:event="DOMActivate" nodeset="." at="last()"
if="count(../bf:subject[@rdf:resource[. = 'http://id.loc.gov/vocabulary/geographicAreas/s-ag']]) > 1"
></xf:delete>
</xf:trigger>
</div>
</xf:repeat>
<!-- Add new bf:subject elements that can take an arbitrary value -->
<xf:trigger ref="bf:subject[@rdf:resource = '']">
<xf:label>+</xf:label>
<xf:action ev:event="DOMActivate">
<xf:insert nodeset="."
origin="instance('bf-Work-template')/bf:Work/bf:subject[@rdf:resource = '']"
at="last()" position="after"></xf:insert>
</xf:action>
</xf:trigger>
<!-- Delete bf:subject elements that can take an arbitrary value -->
<xf:trigger
ref="bf:subject[@rdf:resource = ''][count(../bf:subject[@rdf:resource = '']) > 1]">
<xf:label>-</xf:label>
<xf:action ev:event="DOMActivate">
<xf:delete nodeset="../bf:subject[@rdf:resource = '']" at="last()"
if="count(../bf:subject[@rdf:resource = '']) > 1"></xf:delete>
</xf:action>
</xf:trigger>
<!-- Repeat bf:subject elements that can take an arbitrary value -->
<xf:repeat nodeset="bf:subject[@rdf:resource = '']">
<div style="border:solid black 1px;">
<!-- Value of @rdf:resource is updated using jsPlumb library -->
<span class="label">Subject</span>
<br />
<span>Link to:</span>
<br />
<span class="connect-to">Work</span>
<br />
<span class="connect-to">Topic</span>
<br />
<span class="connect-to">Place</span>
</div>
</xf:repeat>
</xf:repeat>
</div>
</body>
</html>
我就不细说了太多主题,但我会指出,基于XML的RDF操作可能非常容易出错。使用RDF/XML可以用许多不同的方式编写相同的RDF图,并且给定的基于XML的方法不适用于所有这些方法。如果可以的话,使用RDF处理工具将RDF作为RDF处理可能会更好。请参阅[我的答案](http://stackoverflow.com/a/17052385/1281433)至“如何使用Java中的XPath访问OWL文档?”对于一些可能出错的例子。 –
@JoshuaTaylor,谢谢。我意识到使用RDF/XML并不理想,但这里的范围相当有限:使用XForms进行数据输入并将生成的RDF/XML传输到三重存储。从那里,它可以使用SPARQL和RDF处理工具进行处理。据我所知,目前还没有很多用于创建新的RDF数据的数据录入工具。我知道[RDForms](http://rdforms.org/#!index.md),[Graphity](https://github.com/Graphity)和[Callimachus](http://callimachusproject.org/ ),但对于我们的特定项目,我们需要一些更灵活和可定制的东西。 – tat
您能否发布更明确的测试用例?我将你的问题理解为XPath版本,对吗? XForms 2.0允许使用变量,它可能会简化XPath表达式。 XSLTForms最新版本允许var使用。 –