Spec-Zone.ru › Web APIs

XSLTProcessor: метод removeParameter()

Базовая поддержка Широко доступна

Эта функция хорошо зарекомендовала себя и работает на многих устройствах и версиях браузеров. Она доступна в браузерах с июля 2015 года.

  • Подробнее
  • Полная совместимость
  • Отправить отзыв

Метод removeParameter() интерфейса XSLTProcessor удаляет параметр (<xsl:param>) и его значение из стилей, импортированных в процессор.

Синтаксис

removeParameter(namespaceURI, localName)

Параметры

namespaceURI

Пространство имён, связанное с именем параметра. Значение "null" обрабатывается так же, как пустая строка ("").

localName

Имя параметра в связанном пространстве имён.

Возвращаемое значение

None (undefined).

Примеры

Использование removeParameter()

Сначала параметр showItems устанавливается в значение "yes", что позволяет отображать элементы списка в выводе.

После этого параметр showItems удаляется с помощью removeParameter(), и преобразование выполняется снова, в результате чего элементы не отображаются.

HTML

<div id="result"></div>

JavaScript

const xmlString = `
<items>
  <item>Item 1</item>
  <item>Item 2</item>
</items>
`;

const xsltString = `
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name="showItems" select="'yes'"/>
  <xsl:template match="/">
    <!-- If showItems is 'yes', display the list of items -->
    <xsl:if test="$showItems = 'yes'">
      <ul>
        <xsl:for-each select="items/item">
          <li><xsl:value-of select="."/></li>
        </xsl:for-each>
      </ul>
    </xsl:if>
    <!-- If showItems is 'no', display a message -->
    <xsl:if test="$showItems = 'no'">
      <div>No content to show</div>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>
`;

const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlString, "application/xml");
const xsltDoc = parser.parseFromString(xsltString, "application/xml");

const xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsltDoc);

// Set 'showItems' to 'no' and perform the first transformation
xsltProcessor.setParameter(null, "showItems", "no");
const resultContainer = document.getElementById("result");
let resultFragment = xsltProcessor.transformToFragment(xmlDoc, document);
resultContainer.appendChild(resultFragment);

// Add a horizontal rule to separate the results
resultContainer.appendChild(document.createElement("hr"));

// Remove the 'showItems' parameter, reverting it to the default value ('yes')
xsltProcessor.removeParameter(null, "showItems");
resultFragment = xsltProcessor.transformToFragment(xmlDoc, document);
resultContainer.appendChild(resultFragment);

Результат

Спецификации

Спецификация
DOM
# dom-xsltprocessor-removeparameter

Совместимость с браузерами

Рабочие столы Мобильные устройства
Chrome Edge Firefox Opera Safari Chrome Android Firefox для Android Opera Android Safari на iOS Samsung Internet WebView Android
removeParameter 1 12 1 ≤12.1 3.1 18 4 ≤12.1 2 1.0 3

См. также

  • XSLTProcessor.getParameter()
  • XSLTProcessor.setParameter()
  • XSLTProcessor.clearParameters()
  • XSLTProcessor.reset()

© 2005–2024 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/XSLTProcessor/removeParameter

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API