Adding a content tag to the input field inside the template

I am trying to use the new html5 template tag to create a semi-general form that can be placed in several use cases without using too much javascript.

Here is a fiddle showing that I have http://jsfiddle.net/684uH/

my goal is to replace the "Name" in the placeholder text with what would normally be found in the tag <content>

a hypothetical example for my point of view would be:

<div id = "hoster">
    <span class = "inputPlaceholder">Special Name</span>
</div>

<template id = "im-a-template">
    <input type="text" placeholder = <content select = ".inputPlaceholder"></content>>
</template>

Is there a way to do something like this or is it the only way to use javascript to configure it manually?

+4
source share
1 answer

To do this, use XSLT on the client:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="html5.xhtml"?>
<xsl:stylesheet version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"
            >
<xsl:output method="xml" encoding="utf-8" version="" indent="yes" standalone="no" media-type="text/html" omit-xml-declaration="no" doctype-system="about:legacy-compat" />

<!-- Run default templates on the xsl-stylesheet element above-->
<xsl:template match="xsl:stylesheet">
  <xsl:apply-templates/>
</xsl:template>

<!-- Run this template on the root node -->
<xsl:template match="/">
  <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    </head>
    <body>
      <div id="hoster">
        <span class="inputPlaceholder">Special Name</span>
      </div>

      <!-- Reuse the value of the node with the inputPlaceholder class -->
      <template id="im-a-template">
        <input type="text" placeholder="{//node()[@class='inputPlaceholder']}"/>
      </template>
    </body>
  </html>
</xsl:template>

</xsl:stylesheet>

:

  • html5.xhtml ( <?xml-stylesheet href )
  • script <template> polyfill

-1

Source: https://habr.com/ru/post/1536518/


All Articles