Reputation: 1011
I am a complete noob when it comes to xslt and need some help with the following...
I have written an xslt which outputs what I want except for the header. This is what I want to appear:
<etd_ms:thesis xmlns:etd_ms="http://www.ndltd.org/standards/metadata/etdms/1.0/"
xsi:schemaLocation="http://www.ndltd.org/standards/metadata/etdms/1.0/
http://www.ndltd.org/standards/metadata/etdms/1.0/etdms.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
This is what I get with my transform:
<etd_ms:thesis
xsi:schemaLocation="http://www.ndltd.org/standards/metadata/etdms/1.0/
http://www.ndltd.org/standards/metadata/etdms/1.0/etdms.xsd">
Here is the relevant portion of the transform itself:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:etd_ms="http://www.ndltd.org/standards/metadata/etdms/1.0/"
xsi:schemaLocation="http://www.ndltd.org/standards/metadata/etdms/1.0/
http://www.ndltd.org/standards/metadata/etdms/1.0/etdms.xsd">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:copy-of select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
rest of code....
How do I accomplish what I want. I though this line would do what I want:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:etd_ms="http://www.ndltd.org/standards/metadata/etdms/1.0/"
xsi:schemaLocation="http://www.ndltd.org/standards/metadata/etdms/1.0/ http://www.ndltd.org/standards/metadata/etdms/1.0/etdms.xsd">
Here is an example of the input:
<generic_etd>
<dc.creator>Some Person</dc.creator>
<dc.date>2006</dc.date>
<dc.description.abstract>Long lines of text</dc.description.abstract>
<dc.description.note>Masters Abstracts</dc.description.note>
<dc.format>application/pdf</dc.format>
<dc.format>105 p.</dc.format>
<dc.format>2.15 MB</dc.format>
<dc.language>eng</dc.language>
<dc.publisher>Publisher</dc.publisher>
<dc.subject>Ecology.</dc.subject>
<dc.title>My awesome title.</dc.title>
</generic_etd>
Added an example of the code here
But it isn't doing what I want it to. Where have I gone wrong?
Upvotes: 0
Views: 1188
Reputation: 117073
Let me suggest the following as the starting point for your transformation:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:etd_ms="http://www.ndltd.org/standards/metadata/etdms/1.0/">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/generic_etd">
<etd_ms:thesis xsi:schemaLocation="http://www.ndltd.org/standards/metadata/etdms/1.0/ http://www.ndltd.org/standards/metadata/etdms/1.0/etdms.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:apply-templates select="@*|node()"/>
</etd_ms:thesis>
</xsl:template>
<xsl:template match="*">
<xsl:element name="etd_ms:{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
When the above is applied to your example input, the result will be:
<?xml version="1.0" encoding="UTF-8"?>
<etd_ms:thesis xmlns:etd_ms="http://www.ndltd.org/standards/metadata/etdms/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ndltd.org/standards/metadata/etdms/1.0/ http://www.ndltd.org/standards/metadata/etdms/1.0/etdms.xsd">
<etd_ms:dc.creator>Some Person</etd_ms:dc.creator>
<etd_ms:dc.date>2006</etd_ms:dc.date>
<etd_ms:dc.description.abstract>Long lines of text</etd_ms:dc.description.abstract>
<etd_ms:dc.description.note>Masters Abstracts</etd_ms:dc.description.note>
<etd_ms:dc.format>application/pdf</etd_ms:dc.format>
<etd_ms:dc.format>105 p.</etd_ms:dc.format>
<etd_ms:dc.format>2.15 MB</etd_ms:dc.format>
<etd_ms:dc.language>eng</etd_ms:dc.language>
<etd_ms:dc.publisher>Publisher</etd_ms:dc.publisher>
<etd_ms:dc.subject>Ecology.</etd_ms:dc.subject>
<etd_ms:dc.title>My awesome title.</etd_ms:dc.title>
</etd_ms:thesis>
Upvotes: 1