最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

xproc - How can I store xpath value in a variable? - Stack Overflow

matteradmin6PV0评论

With XProc I try to get value returned by a XPath on a loaded document and store it in a variable to apply next.

input.xml

<root>
 <element id="test"/>
</root>

test.xpl

<p:load name="load-source-document" href="input.xml"/>
<p:variable select="/root/element/@id"/>

I tried this with Calabash but I get following error:

Cannot invoke "String.startsWith(String)" because "lexicalQName" is null

With XProc I try to get value returned by a XPath on a loaded document and store it in a variable to apply next.

input.xml

<root>
 <element id="test"/>
</root>

test.xpl

<p:load name="load-source-document" href="input.xml"/>
<p:variable select="/root/element/@id"/>

I tried this with Calabash but I get following error:

Cannot invoke "String.startsWith(String)" because "lexicalQName" is null

Share Improve this question edited Nov 18, 2024 at 22:00 isherwood 61.2k16 gold badges122 silver badges170 bronze badges asked Nov 18, 2024 at 21:59 NicolasNicolas 12 bronze badges 1
  • Please don't tag your title question. See How to Ask. – isherwood Commented Nov 18, 2024 at 22:01
Add a comment  | 

1 Answer 1

Reset to default 0

Yes, it is possible to store the xpath value into the variable. Try updating your code to:

test.xpl

<p:declare-step xmlns:p="http://www.w3./ns/xproc">
  <p:variable name="id-value" select="doc('input.xml')/root/element/@id"/>
  <p:log message="Value is: {$id-value}"/>
</p:declare-step>

Getting the ID value can store into the variable like so.

Post a comment

comment list (0)

  1. No comments so far