Copied to clipboard

Flag this post as spam?

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


  • Owen 13 posts 105 karma points
    Apr 09, 2019 @ 11:26
    Owen
    0

    Referencing form fields in XSLT

    I'm new to XSLT and am trying to create a basic file to use on one of my forms so when a user submits they get a confirmation email.

    I just want to pull in the user's name into that email but I can't figure out how to reference it. The field is {yourName}.

    Can anyone help? Using Umbraco 7.7.6.

    Thanks

    Owen

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 09, 2019 @ 12:25
    Jan Skovgaard
    0

    Hi Owen

    Can you share what your current XSLT looks like please? :-)

    /Jan

  • Owen 13 posts 105 karma points
    Apr 09, 2019 @ 12:30
    Owen
    0

    Hi,

    This is what I've got:

    <?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="/">
    <p>Dear {yourName},</p>
    <p>Thanks for your enquiry.</p>
    <p>We will aim to get back to you soon.</p>
    <p>Regards</p>
    <p>CIEH</p>
    </xsl:template>
    

    The {yourName} field in my form is the one I want to pull through to the email.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 09, 2019 @ 14:55
    Jan Skovgaard
    0

    Hi Owen

    If I remember correctly you should be able to write something like this

    <xsl:value-of select="$records//fields/*[caption='YourName']//value"/>
    

    Please note I can't remember how the caption is cased so it could be that you need to look for "yourName".

    You can see what XML you get by using <xsl:copy-of select="$records" /> - A little trick is to write it out in a <textarea> and then copy the output into your prefered code editor to get a better idea of the context you're looking into. You can do it like this

    <textarea>
    <xsl:copy-of select="$records" />
    </textarea>
    

    If you need to render more advanced stuff at a later point then this little snippet from mr. XSLT aka Chriztian Steinmeier might come in handy for you https://gist.github.com/greystate/2cb2c1f9d2f8085b23e4

    I hope this helps :-)

    /Jan

  • Owen 13 posts 105 karma points
    Apr 09, 2019 @ 15:56
    Owen
    0

    Thanks for your help. Unfortunately this isn't working. Am I missing some other code? The email I get through is:

    Dear {yourName},

    Thanks for your enquiry.

    We will aim to get back to you soon.

    Regards

    CIEH

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 09, 2019 @ 16:25
    Jan Skovgaard
    0

    Hi Owen

    So your code looks like this now?

    <?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="/">
    <p>Dear <xsl:value-of select="$records//fields/*[caption='YourName']//value"/>,</p>
    <p>Thanks for your enquiry.</p>
    <p>We will aim to get back to you soon.</p>
    <p>Regards</p>
    <p>CIEH</p>
    </xsl:template>
    

    If so did you try switching between uppercase and lowercase when writing "YourName" or "yourName" ?

    I guess it's not possible to check the output using the <textarea> in this scenario since it's a pretty tedious process to make the change and test it.

    If I remember correctly you will also need to copy overwrite the XSLT file in the media library everytime you make a change to it and test again.

    /Jan

  • Owen 13 posts 105 karma points
    Apr 10, 2019 @ 12:31
    Owen
    100

    My code is:

    <?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="/">
    <p>Dear <xsl:value-of select="$records//fields/*[caption='yourName']//value"/>,</p>
    <p>Thanks for your enquiry.</p>
    <p>We will aim to get back to you soon.</p>
    <p>Regards</p>
    <p>CIEH</p>
    </xsl:template>
    </xsl:stylesheet>
    

    I've tried switching between uppercase and lowercase ('yourName', 'YourName') but nothing seems to work. I am overwriting the XSLT file in the media library every time.

  • Brita Curum 9 posts 79 karma points
    Apr 15, 2019 @ 06:28
    Brita Curum
    0

    Hi Owen,

    I think the below code format may help. Please give it a try.

    <xsl:value-of select="$records//fields/child::* [caption = 'Your Name']//value"/>
    

    Try NOT using the form field alias name & see if it works..

    ~Brita

  • Owen 13 posts 105 karma points
    Apr 15, 2019 @ 12:43
    Owen
    2

    Hi Brita,

    It works! Using the field question rather than the alias pulls through the data. Hadn't thought about doing that.

    Thank you so much!

    Owen

Please Sign in or register to post replies

Write your reply to:

Draft