简体   繁体   English

处理撒克逊人:评估异常

[英]Dealing with saxon:evaluate exception

I have an XBL file where I can pass some arguments from my form, let's say : 我有一个XBL文件,可以在其中传递表单中的一些参数,例如:

<my-xbl arg1='' arg2=''>
</my-xbl>

<xf:input ref='@arg1'/>
<xf:input ref='@arg2'/>

Then I have something like this : 然后我有这样的事情:

<xf:model>
    <xf:action id="populate-data-binding">                         
        <xf:action context="instance('sub')"
                   ev:event="xforms-submit-done"
                   ev:observer="my-submission">                     
            <xf:action>        
                <xf:var as="xs:string" name="control-value" value="saxon:evaluate(instance('arg1'))"/>  
                <xf:var as="xs:string" name="control-name"  value="saxon:evaluate(instance('arg2'))"/>
                <xf:setvalue ref="xxf:instance('fr-form-instance')//*[name() = $control-name]"
                             value="$control-value"/>
           </xf:action>
    </xf:action>
</xf:model>

The problem is when arg1 is empty string (it means that in my form when I press Control settings and skipp arg1 field, just leaving it empty) then my form crashes. 问题是当arg1是空字符串时(这意味着在我的窗体中,当我按Control设置并跳过arg1字段时,只将其保留为空)会导致我的窗体崩溃。 When I insert '' or anything but empty string (asd, q, anything) as arg1 everything is ok. 当我插入''或除空字符串(asd,q,任何东西)以外的任何内容作为arg1一切正常。 So now I would like to do something like 所以现在我想做些类似的事情

<xf:var as="xs:string" name=".." value="if(@arg1 ='null') then 'asd'
 else 'saxon:evaluate(instance('arg1'))'/>

It doesn't work, obviously because quotes issue (condition must be between '' and I cannot put any quotes inside) and probably something else. 这行不通,显然是因为引号引起了(条件必须在''之间''并且我不能在其中输入任何引号)以及其他可能的原因。 Could someone help me fix this ? 有人可以帮我解决这个问题吗? Thanks in advance. 提前致谢。

UPDATE : 更新:

I guess I was a little bit unprecise. 我想我有点不准确。 To make things clear, arg1 is an ID of xf:input in my form. 为了清楚arg1arg1是我表单中xf:input的ID。 When form gets loaded I call a REST service (you've helped me with this once, Event xforms-model-construct-done behaviour ) and it sends me back some data. 加载表单后,我会调用REST服务(您曾经为我提供过帮助, Event xforms-model-construct-done behavior ),它向我发送了一些数据。 Now I would like to populate data to my xf:inputs and the code above does it very well. 现在,我想将数据填充到我的xf:inputs中,上面的代码做得很好。 The problem is that in my XBL I have plenty of parameters, not just arg1 , arg2 , it looks more like 问题是在我的XBL中,我有很多参数,而不仅仅是arg1arg2 ,它看起来更像

<my-xbl arg1 = '' arg2 = '' ... arg19 = '' arg20 = ''/>

Now, when in my form I go to control's basic settings I have to fill all the paraemters arg1...20 . 现在,当我进入表单的基本控件时,我必须填写所有参数arg1...20 I would like to fill only those I need, which is usually 3 or 4 and leave the others blank. 我只想填写我需要的那些(通常为3或4),其余的留为空白。 The problem is that I cannot do that, because that way my form crashes and it's because saxon:evalute throws an exception if its argument is null. 问题是我不能这样做,因为那样我的表单会崩溃,这是因为saxon:evalute的参数为null时会引发异常。

(Also to mention everything, but I don't think it's relevant here but it may help you to understand my code above : in real, arg2 is an ID of xf:input but arg1 is something like a path to resource in webservice, fe I have arg2 = "'firstname'" which refers to my xf:input and arg1 =" //CUSTOMER/FIRSTNAME" (no quotes) and my REST service URL is http://www.thomas-bayer.com/sqlrest/CUSTOMER/2/ . This way I can choose that under xf:input of id 'firstname' I want to insert only firstname of the whole data I got from webservice. Then again, arg4 would be like 'lastname' and arg3 would be //CUSTOMER/LASTNAME and so on. As I said, don't think it's relevant here) (也要提及所有内容,但我认为这里并不重要,但它可能有助于您理解上面的代码:实际上, arg2xf:input的ID,而arg1类似于Web服务中资源的路径,fe我有arg2 = "'firstname'" ,它指向我的xf:input和arg1 =" //CUSTOMER/FIRSTNAME" (无引号),我的REST服务URL为http://www.thomas-bayer.com/sqlrest/CUSTOMER/2/这样我可以选择在xf: id为'firstname' 输入下 ,我只想插入从网络服务获得的全部数据的名字,然后arg4就像是'lastname'而arg3是//CUSTOMER/LASTNAME ,依此类推。就像我说的,这里不重要)

That's why I wanted to check empty value and I guess your code should have helped me - unfortunately it's not working. 这就是为什么我想检查空值的原因,我想您的代码应该对我有所帮助-不幸的是,它不起作用。 My form doesn't crash anymore, but also data is not populating into xf:inputs . 我的表单不再崩溃,但是数据也没有填充到xf:inputs Maybe because this misunderstanding ? 也许是因为这种误解? Thanks. 谢谢。

<xf:var
    as="xs:string"
    name="..."
    value="
        if(@arg1 ='null')
        then 'asd'
        else 'saxon:evaluate(instance(''arg1''))"/>

To test for a blank string, better use normalize-space() . 要测试一个空字符串,最好使用normalize-space() Also, I guess that instance('arg1') is where the value is stored in both cases: 另外,我猜这两种情况下都将instance('arg1')存储在其中:

<xf:var
    as="xs:string"
    name="..."
    value="
        if (normalize-space(instance('arg1')) = '')
        then 'asd'
        else 'saxon:evaluate(instance(''arg1''))'
"/>

But I am a bit unclear on why you need to quote the saxon:evaluate() call. 但是对于您为什么需要引用saxon:evaluate()调用,我还是不清楚。 Do you want the variable to hold: 您是否要保留变量:

  1. the result of the evaluation? 评估结果?
  2. or an XPath expression? 或XPath表达式?

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

相关问题 异常处理:评估多个语句 - Exception handling: evaluate multiple statements 科拉兹序列。 处理异常处理 - Collatz sequence. Dealing with exception handling 处理异常后恢复的 Pythonic 方式 - Pythonic way to resume after dealing with Exception 如何在即时窗口中评估未处理的异常属性 - How to evaluate unhandled exception properties in immediate window 在Haskell中处理“内存不足”异常/堆栈溢出时如何使用“跟踪”? - How to use “trace” when dealing with an “out of memory” exception/stackoverflow in Haskell? WP7-使用基于异步JAVA的SOAP服务异常处理进行处理 - WP7 -Dealing with Async JAVA based SOAP Service Exception Handling 在处理n个层时,在调用堆栈中捕获异常高? - Catch Exception high in the call stack- when dealing with n tiers? 在PHP中使用工厂处理大量(可能的)异常引发? - Dealing with a lot of (possible) exception to throw using a factory in PHP? 根据Exception.Message处理VB.NET中的异常 - Dealing with exceptions in VB.NET in terms of Exception.Message Wicked-Good-XPath评估xPathResult包含[Exception:TypeError] - Wicked-Good-XPath Evaluate xPathResult contains [Exception: TypeError]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM