Xslt &引用;应为QName";-尝试从属性值创建元素
尝试使用XSL样式表转换简单的XML文档。我现在正在使用XMLspy,但最终目标是浏览者 XML:Xslt &引用;应为QName";-尝试从属性值创建元素,xslt,namespaces,Xslt,Namespaces,尝试使用XSL样式表转换简单的XML文档。我现在正在使用XMLspy,但最终目标是浏览者 XML: <doc> <str name="organizationName">Me</str> <str name="rights">BY-NC</str> <str name="date">2011-05-23</str> <str name="type">Collecti
<doc>
<str name="organizationName">Me</str>
<str name="rights">BY-NC</str>
<str name="date">2011-05-23</str>
<str name="type">Collection</str>
<bool name="collectionPubliclyVisible">true</bool>
<str name="publisher">Pub</str>
<str name="creator">Me</str>
<long name="id">2656</long>
<int name="rank">2</int>
<str name="contributor">ME</str>
<str name="description">This Collection archives 900+ feeds from the network of US based NOAA observation stations recording current climatic conditions, in addition to a daily constructed XML Zip file generated by NOAA.</str>
<str name2="name">NOAA - XML Feeds of Observed Current Conditions</str>
<date name="updated_dt">2011-06-03T21:04:56Z</date>
<str name="relation"/>
<str name="format">zip</str>
<date name="created_dt">2011-05-31T22:36:07Z</date>
<date name="timestamp">2011-06-17T21:54:24.116Z</date>
</doc>
我
BY-NC
2011-05-23
收集
真的
酒吧
我
2656
2.
我
除了NOAA生成的每日构造的XML Zip文件外,该集合还存档了来自美国NOAA观测站网络记录当前气候条件的900多个提要。
NOAA-观测到的当前条件的XML提要
2011-06-03T21:04:56Z
拉链
2011-05-31T22:36:07Z
2011-06-17T21:54:24.116Z
XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:element name="metadata">
<xsl:apply-templates select="doc"/>
</xsl:element>
</xsl:template>
<xsl:template match="doc">
<xsl:apply-templates select="child::node()"/>
</xsl:template>
<xsl:template match="child::node()">
<element name="{@name}" xmlns="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="."/>
</element>
</xsl:template>
</xsl:stylesheet>
非常感谢,我做了几个小时都没有用
-Graham您正在尝试使用
name
属性创建输出元素:
<element name="{@name}" xmlns="http://www.w3.org/1999/XSL/Transform">
我不确定您希望输出什么样的XML,但是您可以尝试使用以下XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>
<xsl:template match="/">
<metadata>
<xsl:apply-templates select="doc/*"/>
</metadata>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{@*}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
结果XML:
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<organizationName>Me</organizationName>
<rights>BY-NC</rights>
<date>2011-05-23</date>
<type>Collection</type>
<collectionPubliclyVisible>true</collectionPubliclyVisible>
<publisher>Pub</publisher>
<creator>Me</creator>
<id>2656</id>
<rank>2</rank>
<contributor>ME</contributor>
<description>This Collection archives 900+ feeds from the network of US based NOAA
observation stations recording current climatic conditions, in addition to a daily
constructed XML Zip file generated by NOAA.</description>
<name>NOAA - XML Feeds of Observed Current Conditions</name>
<updated_dt>2011-06-03T21:04:56Z</updated_dt>
<relation/>
<format>zip</format>
<created_dt>2011-05-31T22:36:07Z</created_dt>
<timestamp>2011-06-17T21:54:24.116Z</timestamp>
</metadata>
我
BY-NC
2011-05-23
收集
真的
酒吧
我
2656
2.
我
该收藏收藏了美国国家海洋和大气管理局网络的900多条信息
记录当前气候条件的观测站,以及每日
由NOAA生成的构造XML Zip文件。
NOAA-观测到的当前条件的XML提要
2011-06-03T21:04:56Z
拉链
2011-05-31T22:36:07Z
2011-06-17T21:54:24.116Z
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<organizationName>Me</organizationName>
<rights>BY-NC</rights>
<date>2011-05-23</date>
<type>Collection</type>
<collectionPubliclyVisible>true</collectionPubliclyVisible>
<publisher>Pub</publisher>
<creator>Me</creator>
<id>2656</id>
<rank>2</rank>
<contributor>ME</contributor>
<description>This Collection archives 900+ feeds from the network of US based NOAA
observation stations recording current climatic conditions, in addition to a daily
constructed XML Zip file generated by NOAA.</description>
<name>NOAA - XML Feeds of Observed Current Conditions</name>
<updated_dt>2011-06-03T21:04:56Z</updated_dt>
<relation/>
<format>zip</format>
<created_dt>2011-05-31T22:36:07Z</created_dt>
<timestamp>2011-06-17T21:54:24.116Z</timestamp>
</metadata>