#xslt #xslt-1.0
#xslt #xslt-1.0
Вопрос:
Используя xsltproc, как я могу выводить разделы CDATA без окружающего пространства, если форматировщик, который мне нужен, использует форматы вокруг CDATA, подобные этому, вставляя пространство? Нет необходимости использовать xsl:текст. Я также попробовал xsl:значение, но не смог понять, как использовать CDATA в xsl:значение. (Я могу удалить пространство вокруг CDATA, но форматер просто добавляет его обратно).
lt;?xml version="1.0" encoding="UTF-8"?gt; lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"gt; lt;xsl:output method="text" version="1.0" encoding="UTF-8" indent='no' /gt; lt;xsl:strip-space elements="*" /gt; lt;xsl:template match="/"gt; lt;xsl:textgt; lt;![CDATA[/* * Licensed under the Apache License, Version 2.0 (the "License"); */ ]]gt; lt;/xsl:textgt; lt;xsl:textgt; lt;![CDATA[/* * Licensed under the Apache License, Version 2.0 (the "License"); */ ]]gt; lt;/xsl:textgt; lt;/xsl:templategt; lt;/xsl:stylesheetgt;
Выход
jonsmirl@ares:~/aosp/blogs/jonsmirl.github.io/xml$ xsltproc test.xsl test.xsl /* * Licensed under the Apache License, Version 2.0 (the "License"); */ /* * Licensed under the Apache License, Version 2.0 (the "License"); */ jonsmirl@ares:~/aosp/blogs/jonsmirl.github.io/xml$
Желаемый результат
jonsmirl@ares:~/aosp/blogs/jonsmirl.github.io/xml$ xsltproc test.xsl test.xsl /* * Licensed under the Apache License, Version 2.0 (the "License"); */ /* * Licensed under the Apache License, Version 2.0 (the "License"); */ jonsmirl@ares:~/aosp/blogs/jonsmirl.github.io/xml$
Это решение работает, моя ошибка заключалась в том, что я думал, что текст должен быть внутри CDATA, чтобы форматер оставил его в покое.
lt;?xml version="1.0" encoding="UTF-8"?gt; lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"gt; lt;xsl:output method="text" version="1.0" encoding="UTF-8" indent='no' /gt; lt;xsl:strip-space elements="*" /gt; lt;xsl:template match="/"gt; lt;xsl:textgt;/* * Licensed under the Apache License, Version 2.0 (the "License"); */ lt;/xsl:textgt; lt;xsl:textgt;/* * Licensed under the Apache License, Version 2.0 (the "License"); */ lt;/xsl:textgt; lt;/xsl:templategt; lt;/xsl:stylesheetgt;
Комментарии:
1. Почему какой-либо раздел CDATA? Если вы хотите контролировать пробелы и отступы
xsl:text
, это инструмент.
Ответ №1:
Это решение работает, моя ошибка заключалась в том, что я думал, что текст должен быть внутри CDATA, чтобы форматер оставил его в покое.
lt;?xml version="1.0" encoding="UTF-8"?gt; lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"gt; lt;xsl:output method="text" version="1.0" encoding="UTF-8" indent='no' /gt; lt;xsl:strip-space elements="*" /gt; lt;xsl:template match="/"gt; lt;xsl:textgt;/* * Licensed under the Apache License, Version 2.0 (the "License"); */ lt;/xsl:textgt; lt;xsl:textgt;/* * Licensed under the Apache License, Version 2.0 (the "License"); */ lt;/xsl:textgt; lt;/xsl:templategt; lt;/xsl:stylesheetgt;