使用xquery

时间:2018-11-11 17:44:02

标签: xml xquery

我需要您的支持,使用xquery将以下示例文本从当前格式格式化为xml格式: 要解析的示例文本:

INTERNATIONAL MOBILE SUBSCRIBER IDENTITY = 001010000000597 TEMPORARY MOBILE SUBSCRIBER IDENTITY = N ACTIVATION STATUS = A

采用以下xml格式

    <item>
<paramName>INTERNATIONAL MOBILE SUBSCRIBER IDENTITY</paramName>
<paramValue>001010000000597</paramValue>
</item>
<item>
<paramName>TEMPORARY MOBILE SUBSCRIBER IDENTITY</paramName>
<paramValue>N</paramValue>
</item>
<item>
<paramName>ACTIVATION STATUS</paramName>
<paramValue>A</paramValue>
</item>

在这种情况下,请任何人可以帮助我

谢谢

1 个答案:

答案 0 :(得分:0)

以下是使用XQuery 3.1和$(document).ready(function() { $("#inputSearch").on("keyup", function() { // search string var value = $(this).val().toLowerCase(); // filter $("#tableContacts tbody tr").each(function() { var self = $(this), td = self.children(), text = self.text().toLowerCase(), workPhone = (td.filter('[data-work-telephone]').data('work-telephone') || '').toString(), mobilePhone = (td.filter('[data-mobile-telephone]').data('mobile-telephone') || '').toString(), match = text.indexOf(value) > -1 || workPhone.indexOf(value) > -1 || mobilePhone.indexOf(value) > -1; self.toggle(match) }); }); });函数的示例:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="inputSearch" type="text" placeholder="Search..." autofocus><br/>
<table id="tableContacts" class="table">
  <thead>
    <tr>
      <th>name</th>
      <th>domain</th>
      <th>email</th>
      <th>work</th>
      <th>mobile</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a href="/contacts/5">Morticia Addams</a></td>
      <td>ghouhl.io</td>
      <td><a href="mailto:Morticia.Addams@ghouhl.io" class="text-truncate">Morticia.Addams@ghouhl.io</a></td>
      <td data-work-telephone="88855512342"><a href="tel:(888) 555-1234 x2">(888) 555-1234 x2</a></td>
      <td data-mobile-telephone="8885552222"><a href="tel:(888) 555-2222">(888) 555-2222</a></td>
    </tr>
    <tr>
      <td><a href="/contacts/6">Someone else</a></td>
      <td>domain.tld</td>
      <td><a href="mailto:Someone.else@domain.tld" class="text-truncate">Someone.else@domain.tld</a></td>
      <td data-work-telephone="1321321546"><a href="tel:(132) 132-1546">(888) 555-1234</a></td>
      <td>N/A</td>
    </tr>
  </tbody>
</table>

https://xqueryfiddle.liberty-development.net/nbUY4kq

在不使用analyze-string运算符的情况下使用XQuery 3.0,该问题看起来像这样:

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";

declare option output:method 'xml';
declare option output:indent 'yes';

declare variable $input-string as xs:string external := 'INTERNATIONAL MOBILE SUBSCRIBER IDENTITY = 001010000000597 TEMPORARY MOBILE SUBSCRIBER IDENTITY = N ACTIVATION STATUS = A';

analyze-string($input-string, '(.+?) = (\S+)')//fn:match
!
<item>
    <paramName>{ fn:group[@nr = 1] => normalize-space() }</paramName>
    <paramValue>{ fn:group[@nr = 2] => normalize-space() }</paramValue>
</item>