xmlxsltxpathumbracoumbraco-contour

XSLT create hyperlink for umbraco form in contour


Contour for Umbraco comes with a workflow option that lets you send an email with an XSLT file applied after a form has been submitted by a user.

It comes with this sample:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="xsl msxsl user umbraco.library">

  <xsl:output method="html" media-type="text/html" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
  doctype-system="DTD/xhtml1-strict.dtd"
  cdata-section-elements="script style"
  indent="yes"
  encoding="utf-8"/>

  <xsl:param name="records" />

  <xsl:template match="/">

    <h3>Intro</h3>
    <p>
      Hello, this is a sample email using xslt to convert a record into a custom email
    </p>

    <h3>the fields</h3>
    <ul>
      <xsl:for-each select="$records//fields/child::*">
        <li>
          <h4>
            Caption: <xsl:value-of select="./caption"/>
          </h4>
          <p>
            <xsl:value-of select=".//value"/>
          </p>
        </li>
      </xsl:for-each>
    </ul>

    <h3>The actual xml</h3>
    <xsl:copy-of select="$records"/>

  </xsl:template>



</xsl:stylesheet>  

One of the form fields is a file upload field for CV's

Ideally I would like it if i could output a proper link.

the field name is 'Upload CV', and currently something like this is being output as simply text in the email it sends:

'/umbraco/plugins/umbracoContour/files/e105a66a-7478-4f95-95ad-d4da3190c6ce/d9e0087e-733b-4b4d-9b54-41d4aa979c11/mycv.pdf'

How can i re-jig this xslt so that when it comes across the 'Upload CV' field it creates a hyperlink rather than just raw text.

the href for the hyperlink will end up being something like:

"http://www.example.com/umbraco/plugins/umbracoContour/files/e105a66a-7478-4f95-95ad-d4da3190c6ce/d9e0087e-733b-4b4d-9b54-41d4aa979c11/mycv.pdf"


Solution

  • You can use the XSLT when/otherwise construct to check for this (I guess the path containing "/umbraco/plugins/umbracoContour/files/" would do, and you can then write in your anchor tag with the appropriate values - appending the http:// bit where needed for the href.

    http://www.w3schools.com/xsl/el_when.asp

    http://www.w3schools.com/xsl/el_otherwise.asp