简体   繁体   English

如何使用XQuery从一系列值中选择属性的特定值?

[英]How to select a specific value of an attribute from a series of values using XQuery?

How do I select a specific attribute value from a series of values using XQuery? 如何使用XQuery从一系列值中选择特定的属性值?

My XML file looks like this: 我的XML文件如下所示:

<unit id="01" xref="entry01 entry02">

How do I select a specific value -- such as entry01 --- from the xref attribute and assign it to a variable? 如何从外部参照属性中选择特定值(例如entry01 ---)并将其分配给变量?

I need to select the individual values from the attribute xref , because additional features for these values are defined later in the file: 我需要从属性xref中选择单个值,因为稍后将在文件中定义这些值的其他功能:

<features xref="entry01" font-size="2">
<features xref="entry02" font-size="3">

I would like to organize the entries into a table such as one exemplified below. 我想将条目组织到一个表中,例如以下示例。 The columns defined by the attributes as follows: unit id, xref, font-size. 属性定义的列如下:单元ID,外部参照,字体大小。

<tbody>
<tr>
<td>01</td>
<td>entry01</td>
<td>2</td>
</tr>
<tr>
<td>01</td>
<td>entry02</td>
<td>3</td>
</tr>
</tbody>

Use fn:tokenize to split at space (or all whitespace) characters, depending on you needs: 使用fn:tokenize分割空格(或所有空白)字符,具体取决于您的需要:

Split at a single space: 在一个空格处分割:

tokenize(<unit id="01" xref="entry01 entry02"/>/@xref, " ")[1]

Allow multiple spaces directly following each other: 允许多个空格紧跟彼此:

tokenize(<unit id="01" xref="entry01  entry02"/>/@xref, " +")[2

Split at a single whitespace (I changed the attribute value to contain a tab character): 在单个空格处分割(我将属性值更改为包含制表符):

tokenize(<unit id="01" xref="entry01    entry02"/>/@xref, "\s")[2]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM