XSL:删除 imageobject fileref 上的前面的文件夹
我想删除前面的“./”和第一个文件夹,如果它没有为属于 imagedata 的任何 fileref 命名为“screenshots”,
那么从
<section xmlns="http://docbook.org/ns/docbook" version="5">
<title>Screenshot</title>
<para xreflabel="New Type" xml:id="manageNewType">
<mediaobject>
<imageobject>
<imagedata fileref="./views/screenshots/manageType1.png" width="100%"/>
</imageobject>
<caption>
<para>New Mode</para>
</caption>
</mediaobject>
</para>
<para xreflabel="Edit Type" xml:id="manageEditType">
<mediaobject>
<imageobject>
<imagedata fileref="./screenshots/manageType2.png" width="100%"/>
</imageobject>
<caption>
<para>Edit Mode</para>
</caption>
</mediaobject>
</para>
</section>
到: 屏幕截图
<para xreflabel="New Type" xml:id="manageNewType">
<mediaobject>
<imageobject>
<imagedata fileref="screenshots/manageType1.png" width="100%"/>
</imageobject>
<caption>
<para>New Mode</para>
</caption>
</mediaobject>
</para>
<para xreflabel="Edit Type" xml:id="manageEditType">
<mediaobject>
<imageobject>
<imagedata fileref="screenshots/manageType2.png" width="100%"/>
</imageobject>
<caption>
<para>Edit Mode</para>
</caption>
</mediaobject>
</para>
</section>
这是我当前的样式表,由于某种原因,它似乎没有执行任何操作...
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="imagedata/@fileref[starts-with(.,'./')
and not(starts-with(.,'./screenshots/'))
]">
<xsl:attribute name="fileref">
<xsl:value-of select="substring-after(substring-after(.,'./'), '/')"/>
</xsl:attribute>
</xsl:template>
<xsl:template match="imagedata/@fileref[starts-with(.,'./screenshots/')]">
<xsl:attribute name="fileref">
<xsl:value-of select="substring-after(.,'./')"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
编辑 添加了 xmlns="http://docbook.org/ns/docbook" version="5" 到部分。
I want to remove preceding './' and first folder if it is not named 'screenshots' for any fileref that belongs to imagedata
So from
<section xmlns="http://docbook.org/ns/docbook" version="5">
<title>Screenshot</title>
<para xreflabel="New Type" xml:id="manageNewType">
<mediaobject>
<imageobject>
<imagedata fileref="./views/screenshots/manageType1.png" width="100%"/>
</imageobject>
<caption>
<para>New Mode</para>
</caption>
</mediaobject>
</para>
<para xreflabel="Edit Type" xml:id="manageEditType">
<mediaobject>
<imageobject>
<imagedata fileref="./screenshots/manageType2.png" width="100%"/>
</imageobject>
<caption>
<para>Edit Mode</para>
</caption>
</mediaobject>
</para>
</section>
To:
Screenshot
<para xreflabel="New Type" xml:id="manageNewType">
<mediaobject>
<imageobject>
<imagedata fileref="screenshots/manageType1.png" width="100%"/>
</imageobject>
<caption>
<para>New Mode</para>
</caption>
</mediaobject>
</para>
<para xreflabel="Edit Type" xml:id="manageEditType">
<mediaobject>
<imageobject>
<imagedata fileref="screenshots/manageType2.png" width="100%"/>
</imageobject>
<caption>
<para>Edit Mode</para>
</caption>
</mediaobject>
</para>
</section>
Here is my current stylesheet that does not appear to be doing nothing for some reason...
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="imagedata/@fileref[starts-with(.,'./')
and not(starts-with(.,'./screenshots/'))
]">
<xsl:attribute name="fileref">
<xsl:value-of select="substring-after(substring-after(.,'./'), '/')"/>
</xsl:attribute>
</xsl:template>
<xsl:template match="imagedata/@fileref[starts-with(.,'./screenshots/')]">
<xsl:attribute name="fileref">
<xsl:value-of select="substring-after(.,'./')"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
Edit Added xmlns="http://docbook.org/ns/docbook" version="5" to section.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此转换:
在提供的 XML 文档上执行时:
产生所需的正确结果:
This transformation:
when performed on the provided XML document:
produces the wanted, correct result: