Using XSLT to get all the get all the elements out of an xhtml file
I have an xhtml file that I'm attempting to transform such that:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/TR/MathML2/dtd/xhtml-m开发者_开发问答ath11-f.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>yada</title>
<meta.....>
</head>
<body>
<p>Something</p>
<p>awesome</p>
</body>
</html>
becomes a
<title>yada</title>
<meta.....>
<p>Something</p>
<p>awesome</p>
The key thing that I'm getting at is that the <head>
and <body>
tags are removed from the document. I don't want to run this through sed or awk to remove them.
Everything that I've tried either has the whole thing in html or converts it all into pure text.
Background on problem: I've got a backup of my blog written in multimarkdown, I'm hoping to put them into different format but I need to get over this issue first.
Note: I started off with the identity template.
something like this? (bear with me, its been ages since I've done XSL actively)
<xsl:for-each select="head">
<xsl:copy-of select="."/>
</xsl:for-each>
<xsl:for-each select="body">
<xsl:copy-of select="."/>
</xsl:for-each>
Sounds like you want the identity transform for everything below html
and body
:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/html|/html/head|/html/body">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Are you sure this isn't the usual namespace problem? Does the input really look like you showed us, or did you leave out the namespaces because you didn't realise they made all the difference?
精彩评论