Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Devin 87 posts 251 karma points
    Mar 13, 2015 @ 09:43
    Devin
    0

    Text string link problem

    Hi guys,

    When I put a full link in the text string using "http://www". the link works but if you only use "www", it just links to the node path.

    Any way around this? I want it so either way, the link will work with or without http://?

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:Examine="urn:Examine"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets Examine ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::* [@nodeTypeAlias='FrontPage']"/>

    <xsl:template match="/">

    <xsl:variable name="facebook" select="$siteRoot/facebook"/>
    <xsl:variable name="twitter" select="$siteRoot/twitter"/>
    <xsl:variable name="googlePlus" select="$siteRoot/googlePlus"/>
    <xsl:variable name="linkedIn" select="$siteRoot/linkedIn"/>
    <xsl:variable name="instagram" select="$siteRoot/instagram"/>

    <ul id="socialIcons">

    <xsl:if test="$facebook != ''">
    <li>
    <a href="{$facebook}" target="_blank">
    <div id="facebook"><xsl:value-of select="normalize-space('')"/></div>
    </a>
    </li>
    </xsl:if>

    <xsl:if test="$twitter != ''">
    <li>
    <a href="{$twitter}" target="_blank">
    <div id="twitter"><xsl:value-of select="normalize-space('')"/></div>
    </a>
    </li>
    </xsl:if>

    <xsl:if test="$googlePlus != ''">
    <li>
    <a href="{$googlePlus}" target="_blank">
    <div id="googlePlus"><xsl:value-of select="normalize-space('')"/></div>
    </a>
    </li>
    </xsl:if>

    <xsl:if test="$linkedIn != ''">
    <li>
    <a href="{$linkedIn}" target="_blank">
    <div id="linkedIn"><xsl:value-of select="normalize-space('')"/></div>
    </a>
    </li>
    </xsl:if>

    <xsl:if test="$instagram != ''">
    <li>
    <a href="{$instagram}" target="_blank">
    <div id="instagram"><xsl:value-of select="normalize-space('')"/></div>
    </a>
    </li>
    </xsl:if>

    </ul>

    </xsl:template>

    </xsl:stylesheet>

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Mar 13, 2015 @ 09:59
    Chriztian Steinmeier
    2

    Hi Devin,

    Have a look at this way of doing it - it's a totally different (yet more "XSLT-like") approach, I know, but you may like it :-)

    At least you should be able to see how you can actually rewrite an attribute depending on some condition, which is what you're looking for...

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umb="urn:umbraco.library"
        exclude-result-prefixes="umb"
    >
    
        <!-- Use HTML mode to avoid hacking empty output elements -->
        <xsl:output method="html" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
        <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::FrontPage" />
    
        <xsl:template match="/">
            <!-- If no fields are filled, don't output anything -->
            <xsl:apply-templates select="$siteRoot[normalize-space(concat(facebook, twitter, googlePlus, linkedIn, instagram))]" />
        </xsl:template>
    
        <xsl:template match="FrontPage">
            <ul id="socialIcons">
                <xsl:apply-templates select="facebook" mode="link" />
                <xsl:apply-templates select="twitter" mode="link" />
                <xsl:apply-templates select="googlePlus" mode="link" />
                <xsl:apply-templates select="linkedIn" mode="link" />
                <xsl:apply-templates select="instagram" mode="link" />
            </ul>
        </xsl:template>
    
        <!-- Generic output template for all services -->
        <xsl:template match="*" mode="link">
            <li>
                <a href="{.}" target="_blank">
                    <!-- Rewrite href attribute if needed -->
                    <xsl:if test="not(starts-with(., 'http'))">
                        <xsl:attribute name="href">
                            <xsl:value-of select="concat('http://', .)" />
                        </xsl:attribute>
                    </xsl:if>
                    <div id="{name()}">
                        <!-- Output service name for accessibility (hide with CSS)? -->
                        <!-- <xsl:value-of select="name()" /> -->
                    </div>
                </a>
            </li>
        </xsl:template>
    
        <xsl:template match="*[not(normalize-space())]" mode="link">
            <!-- No output for empty services -->
        </xsl:template>
    
    </xsl:stylesheet>
    

    /Chriztian

  • Devin 87 posts 251 karma points
    Mar 13, 2015 @ 10:17
    Devin
    0

    You always kill it when it comes to XSLT haha. Thank you greatly, this is perfect. :)

    Definitely an interesting way of doing it.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Mar 13, 2015 @ 10:32
    Chriztian Steinmeier
    0

    Haha - kind words, thanks :-)

  • Daniel 3 posts 73 karma points
    Apr 20, 2018 @ 08:39
    Daniel
    0

    HI Chris .Please can you help with XSLT

    Hi all,

    I have a ticketing system which receives emails formatted in xml sent by users. The system uses an xslt script to convert the xml formatted email into the supported xml format that the system uses to create a ticket.

    Below is an example of the email format which is sent to the system:

    The content found between the tag Description is copied into the description of the ticket is below:

    First Name: Paul Last Name: Bonthuys Email Address: [email protected] Contact Number: 0123456789 How can we help you: Testing

    The issue I am having is that all the text after the email address is cut and not displayed in the ticket description field. So the description field only shows as below:

    First Name: Paul Last Name: Bonthuys Email Address: [email protected]

    Of course I have the option of moving the email address to the end of the Description tag, but I will like to keep the sequence of how the information is displayed i.e. First Name, Last Name, Email Address, Contact Number. I am suspecting that the email address hyperlink is causing the text after it to be cut and not being displayed.

    Below is a sample of my xslt script which copies the content of my email into the ticket description field:

    Anyone has an idea of how I could strip the hyperlink in the email address so that some texts are not cut? XSLT CODE

                                <xsl:variable name="Subject" select = "BusinessObjectList/BusinessObject/EmailMessage/Subject"/>
                                                <xsl:choose>
                                                                <xsl:when test="contains($Subject,'Incident#')"> 
                                                                                <xsl:call-template name="INCIDENT-UPDATE"/> 
                                                                </xsl:when>
    
                                                                <xsl:when test="contains(translate($Subject,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), 'printer')"> 
                                                                                <xsl:call-template name="INCIDENT-KEYWORD-PRINTER"/> 
                                                                </xsl:when>
    
                                                                <xsl:when test="contains(translate($Subject,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), 'outlook')"> 
                                                                                <xsl:call-template name="INCIDENT-KEYWORD-OUTLOOK"/> 
                                                                </xsl:when>
    
                                                                <xsl:when test="contains($Subject,'Service Request#')"> 
                                                                                <xsl:call-template name="SERVICE-REQUEST-UPDATE"/> 
                                                                </xsl:when>
                                                                <xsl:when test="contains($Subject,'Task#')"> 
                                                                                <xsl:call-template name="TASK-UPDATE"/> 
                                                                </xsl:when>
                                                                <xsl:otherwise>
                                                                                <xsl:call-template name="INCIDENT-NEW" />
    
                                                                </xsl:otherwise>
                                                </xsl:choose>
                                </BusinessObjectList>
                </xsl:template>
    
    
    
    
    
    
    
    
    
                <xsl:template name="INCIDENT-NEW">
                                <!-- 
                                                Erzeugt aus der e-Mail den XML Code zum Aktualisieren Anlage eines neuen Incidents
                                                - Die Attachments werden dem Incident hinzugefĆ¼gt
    
                                                Beispielaufruf: 
                                                <xsl:call-template name="INCIDENT-NEW" />
                                -->
    <!-- find the profile link recid of the email sender -->
                                <xsl:variable name="profilelink_recid">
    
                                <!-- for each RelatedBusinessObject -->
                               <xsl:for-each select="BusinessObjectList/BusinessObject/RelatedBusinessObjectList/RelatedBusinessObject/BusinessObject">
                                                <xsl:choose>
                                                                <xsl:when test="@Name = 'Employee'">
                                                                                <xsl:for-each select="./FieldList/Field">
                                                                                                <xsl:choose>
                                                                                                                <xsl:when test="@Name = 'RecId'">
                                                                                                                               <!-- <xsl:value-of select="."/>-->
                                                                                                                                <xsl:value-of select="'620F9E6687914E61A386572763768870'"/> 
                                                                                                                </xsl:when>
                                                                                                </xsl:choose>
                                                                                </xsl:for-each>
                                                                </xsl:when>
                                                </xsl:choose>
                                </xsl:for-each>
                                </xsl:variable>
    
    
    
    
    <!-- find the profile link category of the email sender -->
                                <xsl:variable name="profilelink_cat">
    
                                <!-- for each RelatedBusinessObject -->
                                <xsl:for-each select="BusinessObjectList/BusinessObject/RelatedBusinessObjectList/RelatedBusinessObject/BusinessObject">
                                                <xsl:choose>
                                                                <xsl:when test="@Name = 'Employee'">
                                                                                <xsl:value-of select="'Employee'"/>
                                                                </xsl:when>
                                                </xsl:choose>
                                </xsl:for-each>
                                </xsl:variable>
    
    <!-- for each BusinessObject -->
                                <xsl:for-each select="BusinessObjectList/BusinessObject">
                                <!-- Set the BO name -->
                                <xsl:element name="BusinessObject">
        <!-- Set BO Name as 'Incident' -->
                                                <xsl:attribute name="Name">
                                                                <xsl:value-of select="'Incident'"/>
                                                </xsl:attribute>
    
        <!-- Set Transaction as 'Insert' -->
        <xsl:element name="Transaction">UpdateAdd</xsl:element>
    
        <!--Unique Key List-->
        <xsl:element name="UniqueKeyList">
                                                <xsl:element name="UniqueKey">
                                                                <xsl:element name="Field">
                                                                                <xsl:attribute name="Name">
                                                                                                <xsl:value-of select="'IncidentNumber'"/>
                                                                                </xsl:attribute>
                                                                </xsl:element>
                                                </xsl:element>
        </xsl:element>
    
        <!-- Field List -->
        <FieldList>
          <!-- Fields -->
                                    <xsl:for-each select="EmailMessage/node()">
                                    <xsl:choose>
                                                                <!-- Incident.Subject = Email.Subject-->
                                                                <xsl:when test="name() = 'Subject'">
                                                                                <xsl:element name="Field">
                                                                                <xsl:attribute name="Name">
                                                                                                <xsl:value-of select="'Subject'"/>
                                                                                </xsl:attribute>
                                                                                <xsl:attribute name="Type">System.String</xsl:attribute>
                                                                                                <xsl:value-of select="."/>
                                                                                </xsl:element>
    
                                                                                 <xsl:element name="Field">
                                                                                <xsl:attribute name="Name">
                                                                                                <xsl:value-of select="'Category'"/>
                                                                                </xsl:attribute>
                                                                                <xsl:attribute name="Type">System.String</xsl:attribute>
                                                                                                <xsl:value-of select="."/>
                                                                                </xsl:element>
    
    
                                                                </xsl:when>
    
                                                                <xsl:when test="name() = 'Body'">
    
    
    
                                                                <xsl:variable name="emailbody" method="html" indent="yes" >
    

                                </xsl:element>
    
    </xsl:for-each>
    
                </xsl:template>
    

    TIA.

Please Sign in or register to post replies

Write your reply to:

Draft