我有一个输入xml,在我的xsl中我调用了一个模板.模板内的第一个标签显示为空的xmlns属性,如下所示
<Section xmlns="">
Run Code Online (Sandbox Code Playgroud)
可以在xslt中消除此属性吗?
请在这件事上给予我帮助..
我只是添加了我的代码示例,
Input.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<List>
<Sections>
<Section>
<Column>a</Column>
<Column>b</Column>
<Column>c</Column>
<Column>d</Column>
<Column>e</Column>
</Section>
</Sections>
</List>
Run Code Online (Sandbox Code Playgroud)
Stylesheet.xsl
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="List">
<report xmlns="http://developer.com/">
<Views>
<xsl:call-template name="Page"/>
</Views>
</report>
</xsl:template>
<xsl:template name="Page">
<Content>
<xsl:for-each select="./Sections/Section">
<Columns>
<xsl:for-each select="./Column">
<Column>
<xsl:attribute name="value">
<xsl:value-of select="."/>
</xsl:attribute>
</Column>
</xsl:for-each>
</Columns>
</xsl:for-each>
</Content>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
output.xml看起来像
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://developer.com/">
<Views>
<Content xmlns="">
<Columns>
<Column value="a"/>
<Column value="b"/>
<Column value="c"/>
<Column value="d"/>
<Column value="e"/>
</Columns>
</Content>
</Views>
Run Code Online (Sandbox Code Playgroud)
我需要<report> …
我有以下XSLT样式表(简化):
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
exclude-result-prefixes="exsl">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="categories">
<category name="one"/>
<category name="two"/>
<category name="three"/>
</xsl:variable>
<xsl:template match="/">
<result>
<xsl:for-each select="exsl:node-set($categories)/category">
<xsl:element name="{@name}">
<!-- THIS IS THE PROBLEMATIC PART -->
<xsl:for-each select="/input/object">
<item>
<xsl:value-of select="."/>
</item>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</result>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
这是指以下源XML文档(也简化):
<?xml version="1.0" encoding="utf-8"?>
<input>
<object category="one">a</object>
<object category="one">b</object>
<object category="two">c</object>
<object category="one">d</object>
<object category="three">e</object>
</input>
Run Code Online (Sandbox Code Playgroud)
对源文档的引用不会产生任何结果; 输出只是空元素,每个类别一个:
<?xml version="1.0" encoding="UTF-8"?>
<result>
<one/>
<two/>
<three/>
</result>
Run Code Online (Sandbox Code Playgroud)
如何使用源文档中的项目"填充"元素?
只是为了澄清,使用不同的方法已经解决了这背后的"真正"问题.我只是想了解为什么这种方法不起作用.
我有一个显示电影列表的XML文件.每部电影都有一些元数据来描述情节,演员,导演等.这是示例结构:
<movies>
<movie>
<title>The Shawshank Redemption</title>
<year>1994</year>
<rated>R</rated>
<released>1994 Oct 14</released>
<runtime>142 min</runtime>
<genres>
<genre>Crime</genre>
<genre>Drama</genre>
</genres>
<directors>
<director>Name Surname</director>
</directors>
<writers>
<writer>Stephen King (short story 'Rita Hayworth and Shawshank Redemption')</writer>
<writer>Frank Darabont (screenplay)</writer>
</writers>
<actors>
<actor>Tim Robbins</actor>
<actor>Morgan Freeman</actor>
<actor>Bob Gunton</actor>
<actor>William Sadler</actor>
</actors>
<plot>Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.</plot>
<languages>
<language>English</language>
</languages>
<countries>
<country>USA</country>
</countries>
<awards>Nominated for 7 Oscars. Another 16 wins and 16 nominations.</awards> …Run Code Online (Sandbox Code Playgroud) 如何转换此 XML 文件:
<file>
<text ID="201" date="2014-05-04">
<user_name>user_11</user_name>
<message> HELLO </message>
</text>
</file>
Run Code Online (Sandbox Code Playgroud)
使用 XSLT 1.0 进入这个 XML 文件:
<doc>
<user name="user_11">
<text id="201" date="2014-05-04"> HELLO </text>
</user>
</doc>
Run Code Online (Sandbox Code Playgroud)
另外,如果您有关于该主题的任何资源,请发布,因为我有更多的 XSLT 文件要编码。谢谢