DIDL XML转换为HTML使用XSLT
我有DIDL的一个非常具体的XML文件,这在一定程度看起来是这样的 - http://en.wikipedia.org/wiki/Digital_Item_Declaration_LanguageDIDL XML转换为HTML使用XSLT
我想这个转换成HTML使用XSLT应该也展开和折叠功能。我尝试了很多东西,但找不到任何解决方案。
任何人都可以帮我解决这个问题吗?
除了特定的命名空间声明之外,它确实是一个常规的XML。
示例XML:
<?xml version="1.0" encoding="utf-8"?>
<did:DIDL xmlns:did="urn:mpeg:mpeg21:2002:02-DIDL-NS" xmlns:didmodel="urn:mpeg:mpeg21:2002:02-DIDMODEL-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<did:Item>
<did:Descriptor>
<did:Statement mimeType="text/plain">Image item which two images</did:Statement>
</did:Descriptor>
<did:Descriptor>
<did:Component>
<did:Resource mimeType="image/png" ref="http://imagearchive.net/path/image.png"/>
</did:Component>
</did:Descriptor>
<did:Choice choice_id="choice1" minSelections="1" maxSelections="1" default="selection1">
<did:Descriptor>
<did:Statement mimeType="text/plain">Choice for selection of image 1 or 2. Digital items do not need to have choices.</did:Statement>
</did:Descriptor>
<did:Selection select_id="selection1">
<did:Descriptor>
<did:Statement mimeType="text/plain">Selection 1</did:Statement>
</did:Descriptor>
</did:Selection>
</did:Choice>
<did:Component>
<did:Condition require="selection1" />
<did:Descriptor>
<did:Statement mimeType="text/plain">Picture 1 text summary</did:Statement>
</did:Descriptor>
<did:Resource mimeType="plain/text">This is a plain text resource which is a text about picture 1</did:Resource>
</did:Component>
<did:Component>
<did:Condition require="selection1" />
<did:Descriptor>
<did:Statement mimeType="text/plain">Picture 1 text#1</did:Statement>
</did:Descriptor>
<did:Descriptor>
<!-- the statement also can contain XML -->
<did:Statement mimeType="text/plain">Picture 1 text#2</did:Statement>
</did:Descriptor>
<did:Resource mimeType="image/jpg" ref="http://picturedatabase.com/path/image1.jpg"/>
<did:Resource mimeType="image/jpg" ref="http://picturedatabasemirror.com/path/image1.jpg"/>
</did:Component>
<did:Component>
<did:Descriptor>
<did:Statement mimeType="text/plain">Picture 2 text#2</did:Statement>
</did:Descriptor>
<did:Resource mimeType="image/jpg" ref="http://picturedatabase.com/path/image1.jpg"/>
<did:Resource mimeType="image/jpg" ref="http://picturedatabasemirror.com/path/image1.jpg"/>
</did:Component>
</did:Item>
</did:DIDL>
下面是一个XSL代码,只用相同的模板..输出会随着输入的相同
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:did="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
下面的代码替换元素<did:Descriptor/>
与<did:CustomElement/>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:did="urn:mpeg:mpeg21:2002:02-DIDL-NS">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()[local-name() = 'Descriptor']">
<xsl:element name="did:CustomElement">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
感谢您的回复! – user1402867
但我想实现扩展和崩溃功能也在这个和输出应该以html和树视图的形式,而不是xml – user1402867
@ user1402867,(1)你是最受欢迎的。 (2)那么你必须发布样本输入XML和期望的HTML输出。尝试一些你最终的想法,在这里发布,得到答案。 –
示例预期输入和期望的输出XML。 –