1

I want to replace href links from some html files. i have tried it with xslt, but php only supports 1.0.

For example: this:

  <link rel="stylesheet" href="../../../ressources/css/multilevel- dropdown.css"
  id="css-menu" />

into this:

<link rel="stylesheet" href="/../../ressources/css/multilevel-dropdown.css"
  id="css-menu" />

XSLT 2.0 Example:

    <xsl:template match="@href | @src">
    <xsl:attribute name="{local-name(.)}"><xsl:value-of select="replace(., '../../', '****')"/></xsl:attribute>
</xsl:template>
  • 1
    What/How exactly are you trying to replace the links with? Where will they be coming from? Show us what you have done in PHP – Naeem Khan Jun 20 '19 at 07:58
  • 1
    If you are using XSLT, can you show the XSLT you have tried so far, and explain the logic you are trying to implement. Thanks! – Tim C Jun 20 '19 at 08:00
  • I have tried to make a for-loop that replace the path in php, but this dont works, because i want to replace the sourcecode and not the content from the web browser. In XSLT, i only have examples that works with xslt 2.0, because the 1.0 dont have any replace function. –  Jun 20 '19 at 08:35
  • Can you show the XSLT 2.0 code please? That way we can suggest the best way to implement the same logic in XSLT 1.0. Thank you! – Tim C Jun 20 '19 at 08:47
  • I have added is in the question ^ –  Jun 20 '19 at 09:08
  • There seems to be an inconsistency in your question unfortunately. In the XSLT you have posted, you are replacing `../../` with `****`, but the XML samples you have shown seem to suggest you want something else, as there is no sign of `****` at all in the expected output. Can you be precise as to what the required logic is please? Thank you! – Tim C Jun 20 '19 at 09:39
  • The **** are only placeholders. I only want to replace something. And this is my function with placeholders –  Jun 20 '19 at 09:46
  • In XSLT 1.0, you would need to use a recursive named template to implement a replace function. See https://stackoverflow.com/questions/3067113/xslt-string-replace as one example. – Tim C Jun 20 '19 at 10:27
  • Why don't you just use `starts-with()` for a test and `substring-after()` to get the part after the `../../`? It should be at the start of the string, shouldn't it? – ThW Jun 20 '19 at 13:04
  • Really i dont now, the XSLT File is from my co-worker, he made this for the project. –  Jun 20 '19 at 13:59

0 Answers0