IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

XSLT lookup using regex Options · View
hfeldma1
Posted: Wednesday, September 21, 2016 1:15:17 PM
Rank: Newbie

Joined: 9/2/2016
Posts: 4
Location: Canada
I'm familiar with using lookup document in XSLT, however I'm hoping it's possible to do the lookup using regex? I've attached a sample from the lookup document:
Code:
<Telsa xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <Row Key1="^[A-Z0-9]+/Cell:eNodeB Function Name=[A-Z0-9]+, Local Cell ID=[0-9]+, Cell Name=.*/CnOperator:CnOperatorId=[0-9]+$" ElementType="CELL_CORE_OPERATOR" RegexReplace="&apos;^([A-Z0-9]+)/Cell:eNodeB Function Name=[A-Z0-9]+, Local Cell ID=([0-9]+), Cell Name=.*/CnOperator:(CnOperatorId=[0-9]+)&apos;, &apos;$1/CELL:$2/$3&apos;"></Row>
  <Row Key1="^\w+-\w+-\w+-\d+/Cell:eNodeB Function Name=[A-Z0-9]+, Local Cell ID=[0-9]+, Cell Name=.*, eNodeB ID=[0-9]+, Cell.*$" ElementType="CELL" RegexReplace="&apos;^\w+-\w+-\w+-\d+/Cell:eNodeB Function Name=([A-Z0-9]+), Local Cell ID=([0-9]+), Cell Name=.*, eNodeB ID=([0-9]+), Cell.*$&apos;, &apos;$1/Cell:$2&apos;"></Row>
  <Row Key1="^\w+-\w+-\w+-\d+/EthernetInterface:Ethernet Interface No.=.*$" ElementType="EthernetInterface" RegexReplace="&apos;^(\w+-\w+-\w+-\d+)/EthernetInterface:Ethernet Interface No.=([0-9]+)$&apos; , &apos;$1/No=$2&apos;"></Row>
  <Row Key1="^[A-Z0-9]+/CELL:Local cell identity=[0-9]+, Cell Name=.*/OPERATOR:CnOperatorId=[0-9]+$" ElementType="CELL_CORE_OPERATOR" RegexReplace="&apos;^([A-Z0-9]+/CELL:)Local cell identity=([0-9]+), Cell Name=.*/OPERATOR:(CnOperatorId=[0-9]+)&apos; , &apos;$1$2/$3&apos;"></Row>
  <Row Key1="^[A-Z0-9]+/Cell:Local cell identity=[0-9]+, Cell Name=.*, eNodeB identity=[0-9]+$" ElementType="CELL" RegexReplace="&apos;^([A-Z0-9]+/Cell:)Local cell identity=([0-9]+), Cell Name=.*, eNodeB identity=[0-9]+$&apos;, &apos;$1$2&apos;"></Row>
  <Row Key1="^[A-Z0-9]+/Cell:eNodeB Function Name=[A-Z0-9]+, Local Cell ID=[0-9]+, Cell Name=.*, eNodeB ID=[0-9]+$" ElementType="CELL" RegexReplace="&apos;^([A-Z0-9]+)/Cell:eNodeB Function Name=[A-Z0-9]+, Local Cell ID=([0-9]+), Cell Name=.*, eNodeB ID=([0-9]+)$&apos;, &apos;$1/Cell:$2&apos;"></Row>
  <Row Key1="^[A-Z0-9]+/Cell:eNodeB Function Name=[A-Z0-9]+, Local Cell ID=[0-9]+, Cell Name=.*, eNodeB ID=[0-9]+$" ElementType="CELL" RegexReplace="&apos;^([A-Z0-9]+)/Cell:eNodeB Function Name=[A-Z0-9]+, Local Cell ID=([0-9]+), Cell Name=.*, eNodeB ID=([0-9]+)$&apos;, &apos;$1/Cell:$2&apos;"></Row>
</Telsa>


This is what I have defined in the XSLT for the lookup:
Code:
<xsl:key name="table-lookup" match="Row" use="@Key1"/>
<xsl:variable name="LookupDoc" select="document('Telsa.xml')/Telsa"/>


So my thinking is I need to change the following somehow, question is to what:
Code:
<xsl:value-of select="key('table-lookup', $curr_key, $LookupDoc)/@ElementType"/>

Martin Honnen
Posted: Wednesday, September 21, 2016 8:27:34 PM
Rank: Advanced Member

Joined: 6/10/2007
Posts: 36
Can you show us the data passed in as $curr_key you want to compare? A key works with an exact value comparison https://www.w3.org/TR/xslt20/#keys with the eq operator so it is not clear what you want to achieve.
hfeldma1
Posted: Wednesday, September 21, 2016 8:51:46 PM
Rank: Newbie

Joined: 9/2/2016
Posts: 4
Location: Canada
Good point, so a sample input (i.e. $curr_key) to the document lookup would be
Code:
LTHAB0113422/Cell:eNodeB Function Name=LTHAB0113422, Local Cell ID=0, Cell Name=LTHAB0113422-000-2100-1-1, eNodeB ID=113422, Cell FDD TDD indication=CELL_FDD/CnOperator:CnOperatorId=0


This should match with the first element (Key1) in the sample document posted. Does XSLT 3.0 maybe support this?
Martin Honnen
Posted: Thursday, September 22, 2016 2:46:05 PM
Rank: Advanced Member

Joined: 6/10/2007
Posts: 36
I don't think a key can solve that but assuming XSLT 2.0 or higher you have regular expression support and can use
Code:

<xsl:value-of select="$LookupDoc/Row[matches($curr_key, @Key1)]/@ElementType"/>
hfeldma1
Posted: Friday, September 23, 2016 6:14:57 PM
Rank: Newbie

Joined: 9/2/2016
Posts: 4
Location: Canada
Thank you so much, works like a charm.
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.