0

XML:

<param name="SomeName">
                      <path>'root.domain.sub1.sub2.sub3.subover9000'</path>
</param>

The root.domain. is a static value, sub1.sub2.sub3.subover9000 is a dynamic value. Where I want to select the sub2 value as output.

My XSLTv1:

<xsl:variable name="Sysid" select="//@name[normalize-space(.) = 'SomeName']/parent::*"/>    
<xsl:variable name="SSafter" select="substring-after( $Sysid, 'root.domain.')"/>
<xsl:variable name="SSbefore" select="substring-before( $SSafter, '.sub3.subover9000')"/>

<xsl:value-of select="$SSbefore"/>

Output:

sub1.sub2

The problem is - I cannot renounce sub1. because its dynamic in different XML files, but I only need sub2.

So how can I say to ignore part between root.domain. and next dot"."?

The rule says:

The expression fn:substring-after("abcdefghi", "--d-e-", "http://www.w3.org/2013/collation/UCA?lang=en;alternate=blanked;strength=primary") returns "fghi".

Which in my view means, when I use:

<xsl:variable name="SSafter" select="substring-after( $Sysid, '--root.domain.-.-')"/>

I should get sub2 as output, but I don't.

Cœur
  • 37,241
  • 25
  • 195
  • 267
MypR
  • 49
  • 7
  • Are you really using a XSLT 3.0 processor? – michael.hor257k Aug 30 '17 at 14:38
  • @michael.hor257k I apologize in advance, that's what I'm using: `` – MypR Aug 30 '17 at 14:43
  • That doesn't mean anything - I am asking about the XSLT **processor engine** you are using. Only yesterday you told us it was limited to XSLT 1.0. If you don't know, find out: https://stackoverflow.com/questions/25244370/how-can-i-check-which-xslt-processor-is-being-used-in-solr/25245033#25245033 – michael.hor257k Aug 30 '17 at 14:49
  • @michael.hor257k You're right, I am wrong. It is vesion 1. Do I need to change it or is there a way to do what I mantioned with version 1? – MypR Aug 30 '17 at 14:55
  • XSLT 1.0 is Turing-complete, so there is a way, but it's awkward. Which specific engine is it? – michael.hor257k Aug 30 '17 at 14:57
  • @michael.hor257k Microsoft – MypR Aug 30 '17 at 15:02

1 Answers1

0

Consider the following example:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:param name="string">root.domain.sub1.sub2.sub3.subover9000</xsl:param>

<xsl:template match="/">
    <result>
        <xsl:value-of select="substring-before(substring-after(substring-after($string, 'root.domain.'), '.'), '.')"/>
    </result>
</xsl:template>

</xsl:stylesheet>

Result

<?xml version="1.0" encoding="UTF-8"?>
<result>sub2</result>

See also: https://stackoverflow.com/a/33841806/3016153 for a generic template to extract N-th token from a delimited string.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • I am appreciated and thanks for provided informations it helps me alot, and it works ofcourse. I only changed `` to make it multi usable for different XML files. – MypR Aug 30 '17 at 15:12