par*_*nza 3 regex xml xslt solr
我需要使用样式表转换将Solr服务器的响应转换为类似XML的格式.Solr模式中的许多字段都是多值的,包括方括号,表示数组.出于显示目的,我想在字段值的开头和结尾删除这些括号.目前,我的XSLT看起来像这样(该示例引用了字段标题并处理没有标题的记录:
<pnx:title>
      <xsl:variable name="title">
              <xsl:choose>
              <xsl:when test="string-length(field[@name='title']) > 0">
              <xsl:value-of select="field[@name='title']" />
              </xsl:when>
              <xsl:otherwise>
              <xsl:value-of select="field[@name='text']" />
              </xsl:otherwise>
              </xsl:choose>
              </xsl:variable>
              <!-- handle empty title -->
              <xsl:choose>
              <xsl:when test="string-length($title) = 0">
              Untitled
              </xsl:when>
              <xsl:otherwise>
              <xsl:value-of select="$title"/>
              </xsl:otherwise>
              </xsl:choose>
              </pnx:title>
Run Code Online (Sandbox Code Playgroud)
我通常会使用substring(string,number,number)从字符串中删除字符,但在这种情况下我不知道最后一个字符的位置.任何的想法?
谢谢,我.
例如:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <xsl:variable name="abc">[11sdf sdsdf sdfds fsdf dsfsdf fsd2]</xsl:variable>
  <xsl:variable name="length" select="string-length($abc)"/>
  <xsl:message><xsl:value-of select=" $length"/></xsl:message>
  <xsl:value-of select="substring($abc,2,($length - 2))"/>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
产出产量:
11sdf sdsdf sdfds fsdf dsfsdf fsd2
Run Code Online (Sandbox Code Playgroud)