nesting XSLT functions substring within contains

I have this working correctly, but I was wondering if there was a way to nest the substring fx within the contains funcion

XML:

<patientRole> 
    <telecom use="HP" value="tel:555-555-2004" />
    <telecom use="HP" value="mailto:aaeveryman@email.com" />

Working XSLT:

<xsl:variable name="PtTelecom" select="ClinicalDocument/recordTarget/patientRole/telecom/@value"/>
<xsl:variable name="PtPhoneNumber" select="$PtTelecom[contains(., 'tel')]"/>
<xsl:variable name="PtPhoneNumberFormat" select="substring-after($PtPhoneNumber, 'tel:')"/>
<xsl:variable name="PtEmail" select="$PtTelecom[contains(., 'mailto')]"/>
<xsl:variable name="PtEmailFormat" select="substring-after($PtEmail, 'mailto:')"/>

Can it be nested something like I want the substring-after tel: if it contains tel:

<xsl:variable name="PtPhoneNumber" select="substring-after(contains($PtTelecom, 'tel'), 'tel:')"/>
<xsl:variable name="PtEmail" select="substring-after(contains($PtTelecom, 'mailto'), 'mailto:')"/>

This didn't return any value so I feel like a) it cant be nested or b) I have something wrong. Any help is appreciated

1 answer

  • answered 2018-10-11 19:48 Tim C

    So, instead of doing this...

    <xsl:variable name="PtPhoneNumber" select="$PtTelecom[contains(., 'tel')]"/>
    <xsl:variable name="PtPhoneNumberFormat" select="substring-after($PtPhoneNumber, 'tel:')"/>
    

    Do this..

    <xsl:variable name="PtPhoneNumberFormat" select="substring-after($PtTelecom[contains(., 'tel')], 'tel:')"/>
    

    So, you are literally replacing the use of the variable with its declaration. Of course, you can now use a different variable name....

    <xsl:variable name="PtPhoneNumber" select="substring-after($PtTelecom[contains(., 'tel')], 'tel:')"/>
    

    And similarly for the email one..

    <xsl:variable name="PtEmail" select="substring-after($PtTelecom[contains(., 'mailto')], 'mailto:')"/>