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="'^([A-Z0-9]+)/Cell:eNodeB Function Name=[A-Z0-9]+, Local Cell ID=([0-9]+), Cell Name=.*/CnOperator:(CnOperatorId=[0-9]+)', '$1/CELL:$2/$3'"></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="'^\w+-\w+-\w+-\d+/Cell:eNodeB Function Name=([A-Z0-9]+), Local Cell ID=([0-9]+), Cell Name=.*, eNodeB ID=([0-9]+), Cell.*$', '$1/Cell:$2'"></Row> <Row Key1="^\w+-\w+-\w+-\d+/EthernetInterface:Ethernet Interface No.=.*$" ElementType="EthernetInterface" RegexReplace="'^(\w+-\w+-\w+-\d+)/EthernetInterface:Ethernet Interface No.=([0-9]+)$' , '$1/No=$2'"></Row> <Row Key1="^[A-Z0-9]+/CELL:Local cell identity=[0-9]+, Cell Name=.*/OPERATOR:CnOperatorId=[0-9]+$" ElementType="CELL_CORE_OPERATOR" RegexReplace="'^([A-Z0-9]+/CELL:)Local cell identity=([0-9]+), Cell Name=.*/OPERATOR:(CnOperatorId=[0-9]+)' , '$1$2/$3'"></Row> <Row Key1="^[A-Z0-9]+/Cell:Local cell identity=[0-9]+, Cell Name=.*, eNodeB identity=[0-9]+$" ElementType="CELL" RegexReplace="'^([A-Z0-9]+/Cell:)Local cell identity=([0-9]+), Cell Name=.*, eNodeB identity=[0-9]+$', '$1$2'"></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="'^([A-Z0-9]+)/Cell:eNodeB Function Name=[A-Z0-9]+, Local Cell ID=([0-9]+), Cell Name=.*, eNodeB ID=([0-9]+)$', '$1/Cell:$2'"></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="'^([A-Z0-9]+)/Cell:eNodeB Function Name=[A-Z0-9]+, Local Cell ID=([0-9]+), Cell Name=.*, eNodeB ID=([0-9]+)$', '$1/Cell:$2'"></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"/>
|
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.
|
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?
|
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"/>
|
Rank: Newbie
Joined: 9/2/2016 Posts: 4 Location: Canada
|
Thank you so much, works like a charm.
|