0
<xsl:variable name="groups" as="element(group)*">
<xsl:analyze-string regex="^^([0-9-]+)([A-Z ]*)[ ]*([\(](.*)[\)])*$" select="/fault/informations/restriction1">
<xsl:matching-substring>
  <group>
     <x><xsl:value-of select="regex-group(1)"/></x>
     <y><xsl:value-of select="regex-group(4)"/></y>
  </group>   
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>

it was allready in XSL Analyze-String -> Matching-Substring into multiple variables

but my question is how to use it on example to concate eg regex-group(1) with other element outside regex path "/fault/informations/restriction2"

so simple IMPUT XML:

<fault >
  <information>

    <reference1>22-00 X (AA - 03 StoLAT)</reference1>

    <opr>Sample sam (66-33) Sample</opr>

  </information>
</fault>

and OUTPUT I would like to have in one element

<mytrouble>
  <trouble12>AA - 03 StoLAT , Sample sam Sample</trouble12>
</mytrouble>

so the rgex group 4 - text inside ( ) from <reference1> and the whole text from opr

ps currently by transforming:

Cannot match item type with required type Error location: xsl:stylesheet / xsl:template / xsl:element / xsl:variable / @as

Details XTTE0570 : The required item type of variable ' groups ' is ' element(Q{http://xml.event/1.0}group) ' , the supplied item type is ' text() '

GREAT THANX for

michael.hor257k

almost there - just the result indicates header

<trouble12 xmlns:fn="http://www.w3.org/2005/xpath-functions">AA - 03 StoLATSample sam Sample</trouble12>
Community
  • 1
  • 1
MiG
  • 79
  • 1
  • 1
  • 8
  • Please show us a small but complete and representative snippet of the XML input and then show us the result you want to create using XSLT 2.0 for that input, explaining the rules. – Martin Honnen Sep 07 '16 at 17:16
  • Are you complainining about the namespace decalration `xmlns:fn="http://www.w3.org/2005/xpath-functions"`? – michael.hor257k Sep 08 '16 at 09:52
  • yes :) but it's not complaining - it was a great help from You really but if there is a way to exclude the declaration I would be double grateful for guidance – MiG Sep 08 '16 at 09:57
  • It is caused by code that you have not shown us. I am guessing you have this declaration in your `xsl:stylesheet` opening tag, and you need to add `exclude-result-prefixes="fn"` in the same place. – michael.hor257k Sep 08 '16 at 10:15
  • @michael-hor257k, of course THANX again – MiG Sep 08 '16 at 10:47

1 Answers1

1

my question is how to use it on example to concate eg regex-group(1) with other element outside regex path "/fault/informations/restriction2"

To refer to another node within the xsl:analyze-string instruction, capture it in a variable first - for example:

<xsl:variable name="opr" select="fault/information/opr" />  
<xsl:analyze-string regex="^^([0-9-]+)([A-Z ]*)[ ]*([\(](.*)[\)])*$" select="fault/information/reference1">
    <xsl:matching-substring>
        <trouble12>
            <xsl:value-of select="regex-group(4)"/>
            <xsl:value-of select="$opr"/>
        </trouble12>
    </xsl:matching-substring>
</xsl:analyze-string>
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51