0

I am trying to replace all http:// instances from the href tags and from the image sources, to https://

<xsl:for-each select="item[position()&lt;2 and position()&gt; 0]"><!-- display 1 - skip none -->
        <article class="395by265-Presentation">
            <a href="{link}" target="_blank">
                <img src="" width="395" height="265" alt="{title}" border="0" class="FBAPP"><xsl:attribute name="src">
                    <xsl:value-of  disable-output-escaping="yes" select="enclosure/@url"/></xsl:attribute>
                </img>
                <div class="synopsis"><xsl:value-of select="description"/></div>
            </a>
        </article>
    </xsl:for-each>

Any help appreciated.

I am using XSLT 1.0.

Trying to access and replace all instances of HTTP.

  • You haven't shown anything that allows someone to understand what you're trying to achieve. At the minimum, show the input XML and some XSLT that tries to address the problem. What you have shown doesn't seem to pertain to the question. – Jim Garrison Apr 17 '13 at 23:41
  • @jim-garrison If you look at: – PandaExpert Apr 18 '13 at 00:31
  • 1
    I think the question is clear enough, as-is, especially taking into account the OP's comment. I would have answered it last night if I'd had time. Voting to re-open. – LarsH Apr 18 '13 at 13:13
  • @PandaExpert, you can use `href="{concat('https://', substring-after(link, 'http://'))}"` (and similarly with `enclosure/@url`). However this will malfunction if the values don't start with `http://`, so you can put in a conditional using `` with ``. This would be my answer if the question weren't closed. – LarsH Apr 18 '13 at 13:17
  • As a separate issue, I'm puzzled why you're outputting the img src with disable-output-escaping. I assume you're trying to avoid escaping ampersands among URL query parameters; but then wouldn't that result in invalid HTML? – LarsH Apr 18 '13 at 13:21
  • @LarsH Thank you! That makes perfect sense. The code I included is legacy from previous developers, and I haven't really used XSLT so I initially left everything as-is. I've removed that bit in the meantime. As a side note, I too thought the question was clear enough (though agree, not perfect), so was taken aback a little by the initial comment and willingness to close the question so quickly. Very much appreciate your response. – PandaExpert Apr 18 '13 at 22:03
  • You're welcome. Yeah, it seems people get trigger-happy sometimes on the "close" button. To me, if a question's shortcomings can be fixed, there's no need to close it, unless the OP has ignored questions and suggestions on how to fix it. – LarsH Apr 19 '13 at 17:40

1 Answers1

1

What version of XSLT are you working with?

XSLT 2.0 supports a replace function:

replace(string,pattern,replace) 

Returns a string that is created by replacing the given pattern with the replace argument.

Example: replace("Bella Italia", "l", "*")
Result: 'Be**a Ita*ia'

Example: replace("Bella Italia", "l", "")
Result: 'Bea Itaia'

Example syntax: <xsl:value-of select="string:replace('Bella Italia','l','')" />
Result: 'Bea Itaia'

Have a look here: https://stackoverflow.com/a/3067130/1846192 for an XSLT 1.0 solution.

Community
  • 1
  • 1
Mathijs Flietstra
  • 12,900
  • 3
  • 38
  • 67
  • Thank you for your response. I am using XSLT 1.0. Is there a solution to this without using a template? I saw in other posts people are using the translate() function with XSLT 1.0. Do you know how I could use that function in this case? – PandaExpert Apr 18 '13 at 00:39
  • 1
    In [XSLT 1.0 translate()](http://zvon.org/xxl/XSLTreference/OutputOverview/function_translate_frame.html) can be used to do replacements when replacing or removing specific characters inside a string. By design it can only "translate" existing characters in a string on a single character by single character basis. Therefore it can not be used to add characters to string, whichever way you twist or turn it. It will always have to replace a preexisting character. – Mathijs Flietstra Apr 18 '13 at 02:54
  • I see, thanks for clarifying that and for your help user1846192. Appreciate your willingness to help. – PandaExpert Apr 18 '13 at 05:28