2
XSLT를 사용하여 XHTML 문서를 XML로 변환하려하지만 현재 입력 문서의 태그와 일치하도록 템플릿을 가져 오는 데 문제가 있습니다. XHTML을 XML로 변환 할 수 있어야합니까? 그렇다면 내 스타일 시트에 오류가 있습니까?XSLT를 사용하여 HTML을 XML로 변환
입력 문서 :
<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>title text</title>
</head>
<body>
<p>body text</p>
</body>
</html>
스타일 시트 :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<article>
<xsl:apply-templates select="html/head"></xsl:apply-templates>
</article>
</xsl:template>
<xsl:template match="html/head">
<head><xsl:text>This is where all the metadata will come from</xsl:text></head>
</xsl:template>
</xsl:stylesheet>
예상 출력
<article>
<head>This is where all the metadata will come from</head>
</article>
감사
감사합니다. 입력 문서의 태그가 네임 스페이스를 사용하여 명시 적으로 선언되지 않았기 때문에 변환시 네임 스페이스를 사용해야한다는 것을 알지 못했습니다. –
JimS
당신은 혼자가 아닙니다. 누군가는 거의 매일이 질문을합니다. –