MiG
MiG

Reputation: 79

XSL use regex group result + other element outside regex path for one outcome element

<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>

Upvotes: 0

Views: 795

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117115

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>

Upvotes: 1

Related Questions