【问题标题】:multi-select input fields in MarkLogicMarkLogic 中的多选输入字段
【发布时间】:2015-05-31 01:19:06
【问题描述】:

我在表单中有一个多选输入字段,在这种情况下,它是一组复选框,但它可能是一个多选下拉列表。 表单中的字段看起来很好,但是在提交表单时请求会引发错误。查询字符串为:

?headings=on&text=on&references=on&book-category[]=mis&book-category[]=bds&book-category[]=gts

PHP 将多选输入字段作为数组处理。我认为 xquery 会将它们视为序列。显然,xquery 无法处理 http 请求中的此类字段。有没有人成功处理 xquery 中的多选输入字段?

这是生成表单字段的xslt,在源代码中看起来非常完美。

    <xsl:for-each select="r:body/sidebar/search:facet[@name='category']/search:facet-value">
    <xsl:variable name="category-display" select="text()"/>
    <xsl:variable name="category-name" select="encode-for-uri(string-join(tokenize(lower-case(text()), ' '), ''))"/>
    <xsl:variable name="category-id" select="encode-for-uri(concat('adv_books_', string-join(tokenize(lower-case(text()), ' '), '')))"/>
    <li>
    <input type="checkbox" name="book-category[]" id="{$category-id}" value="{$category-name}" class="checkbox" />
    <label for="{$category-id}"><xsl:value-of select="$category-display" /></label>
    </li>
    </xsl:for-each>

这是日志中的错误:

2015-03-26 21:16:54.017 Notice: 8040-MYSITE-HTTP: XDMP-QNAMELEXFORM: for $param in xdmp:get-request-field-names() -- Invalid lexical form for QName

我认为 xquery 不喜欢参数 book-category[] 中的括号。

【问题讨论】:

  • 我在这里看不到任何 XQuery。您是否可能在谈论 XPath 问题(嵌入在 XSLT 中)?
  • 不,我发布的代码不包含处理 HTTP 请求的 xQuery。我刚刚发布它是为了说明表单上的实际输入字段没有任何问题。正是调用 xdmp:get-request-field-names() 的 xQuery 函数引发了日志中所见的错误。
  • 这与 XQuery 关系不大,但与您使用的 XQuery 处理器有关。鉴于您提到了 xdmp 方法,我猜您正在使用 MarkLogic。我相应地编辑了问题。

标签: xslt xquery marklogic


【解决方案1】:

MarkLogic 支持具有多个值的 HTTP 参数,在 XQuery 中为值返回一个序列:

http://docs.marklogic.com/xdmp:get-request-field

在 MarkLogic 8 中,您还可以使用 JavaScript:

http://docs.marklogic.com/xdmp.getRequestField

客户端中的 XSLT 似乎没有正确创建 URL 参数。 HTTP 支持多值参数,方法是为每个值重复参数,而不是使用具有值数组的单个参数。 HTTP 中多值参数的语法与用于访问这些值的服务器语言的语法无关。

希望对您有所帮助。

【讨论】:

  • 我认为你是对的,但我不知道如何纠正它。
  • 您是否尝试将“book-category[]”更改为“book-category”?
  • 如果我将其更改为不带括号的书本类别,则不会是多选复选框。
【解决方案2】:

必须输入此位作为“答案”,即使它不是答案,因为评论太长了。该错误是在用于此应用程序的 MVC 框架的文件中引发的,我犹豫是否要更改框架代码:

declare function utils:get-request()
as element(req:request)
{
  element {fn:QName("http://marklogic.com/mvc/request","request")} {
    attribute method {fn:lower-case(xdmp:get-request-method())},
    attribute rewrite-url {xdmp:get-request-url()},
    attribute protocol {xdmp:get-request-protocol()},
    attribute client-ip {xdmp:get-request-client-address()},
    element req:status-code {200},
    element req:message {"OK"},
    element req:session {
      for $field in xdmp:get-session-field-names()
      return
        element {fn:concat("req:",fn:lower-case($field))} {
          xdmp:get-session-field($field)
        }
    },
    element req:params {
      for $param in xdmp:get-request-field-names()
      where fn:not(fn:exists(xdmp:get-request-field-content-type($param)))
      return
        element {fn:concat("req:",fn:lower-case($param))} {
          attribute content-type {xdmp:get-request-field-content-type($param)},
          for $value in xdmp:get-request-field($param) return element req:value {$value}
        }
    },
    (: SOME MORE CODE HERE :)
    }
};

【讨论】:

  • 我试过:for $param in fn:distinct-values(xdmp:get-request-field-names()) 但它也抛出了错误。
猜你喜欢
  • 1970-01-01
  • 2021-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-07
  • 2017-11-23
  • 1970-01-01
  • 2016-01-11
相关资源
最近更新 更多