简体   繁体   English

XSLT使用正则表达式转换值

[英]XSLT transform a value with regex

I am using Saxon 9.8 with xslt3.0 on windows xp to transform a xml database into a normal text file with one database entry per line. 我在Windows XP上使用带有xslt3.0的Saxon 9.8,将xml数据库转换为每行一个数据库条目的普通文本文件。 but I need to process a value with regex and conditional and when I add the following portion of code: 但是当我添加以下代码部分时,我需要使用正则表达式和条件表达式来处理一个值:

  <xsl:analyze-string select="sbtime/@stmerid" 
    regex="([hm]{{1}})([0-9]{{1,2}})([ew]{{1}})([0-9]{{0,2}})">
    <xsl:matching-substring>
    <xsl:choose>
      <xsl:when test="regex-group(3) = 'e'">
        <xsl:text>+</xsl:text>
      </xsl:when>
      <xsl:when test="regex-group(3) = 'w'">
        <xsl:text>-</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>+</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="regex-group(1) = 'h'">
        <xsl:number value="regex-group(2)" format="01"/>
      </xsl:when>
      <xsl:when test="regex-group(1) = 'm'">
        <xsl:text>00:</xsl:text>
        <xsl:number value="regex-group(2)" format="01"/>
        <xsl:text>:</xsl:text>
        <xsl:number value="regex-group(4)" format="01"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>+1</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    </xsl:matching-substring>
  </xsl:analyze-string>

When I add this portion I get the following error code: 当我添加此部分时,我得到以下错误代码:

Transform.exe" -s:db_export_sample.xml -xsl:dbx_dma_zet01.xsl -o:output.txt

Exception non gérée : System.TypeInitializationException: Une exception a été le
vée par l'initialiseur de type pour 'net.sf.saxon.expr.number.NumberFormatter'.
---> System.TypeInitializationException: Une exception a été levée par l'initial
iseur de type pour 'net.sf.saxon.regex.charclass.Categories'. ---> java.lang.Run
timeException: Unable to read categories.xml file
   à net.sf.saxon.regex.charclass.Categories.build()
   à net.sf.saxon.regex.charclass.Categories.getCategory(String cat)
   à net.sf.saxon.regex.charclass.Categories..cctor()
   --- Fin de la trace de la pile d'exception interne ---
   à net.sf.saxon.regex.charclass.Categories.getCategory(String cat)
   à net.sf.saxon.expr.number.NumberFormatter..cctor()
   --- Fin de la trace de la pile d'exception interne ---
   à net.sf.saxon.expr.number.NumberFormatter..ctor()
   à net.sf.saxon.style.XSLNumber.prepareAttributes()
   à net.sf.saxon.style.StyleElement.processAttributes()
   à net.sf.saxon.style.StyleElement.processAllAttributes()
   à net.sf.saxon.style.StyleElement.processAllAttributes()
   à net.sf.saxon.style.StyleElement.processAllAttributes()
   à net.sf.saxon.style.StyleElement.processAllAttributes()
   à net.sf.saxon.style.StyleElement.processAllAttributes()
   à net.sf.saxon.style.StyleElement.processAllAttributes()
   à net.sf.saxon.style.XSLTemplate.processAllAttributes()
   à net.sf.saxon.style.PrincipalStylesheetModule.processAllAttributes()
   à net.sf.saxon.style.PrincipalStylesheetModule.preprocess()
   à net.sf.saxon.style.Compilation.compilePackage(Source source)
   à net.sf.saxon.style.StylesheetModule.loadStylesheet(Source styleSource, Comp
ilation compilation)
   à net.sf.saxon.style.Compilation.compileSingletonPackage(Configuration config
, CompilerInfo compilerInfo, Source source)
   à net.sf.saxon.s9api.XsltCompiler.compile(Source source)
   à net.sf.saxon.Transform.doTransform(String[] args, String command)
   à Saxon.Cmd.DotNetTransform.Main(String[] args)

BTW Sorry about french language in code may not be understandable. BTW对不起,法语在代码中可能无法理解。 I am not used to xslt but It seems to be correct according to xslt and saxon documentation. 我不习惯使用xslt,但是根据xslt和saxon文档,它似乎是正确的。

Best Regards. 最好的祝福。

This was bug 3283 这是错误3283

https://saxonica.plan.io/issues/3283 https://saxonica.plan.io/issues/3283

which was quickly fixed in a maintenance release. 它在维护版本中很快得到修复。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM