XSLT processing problem with asp specific code
I have开发者_C百科 asp file with code below:
<html>
<head>
<link rel="stylesheet" href="<%=bb_style%>"/>
<title>asdf</title>
</head>
I need to include title from this file into another asp file formed by xslt transformation. I use this code:
<xsl:value-of select="document(content)/html/head/title"/>
But I have nothing returned from this code. I blame href="<%=....%>"
but not sure and don't know how to avoid this problem.
<html> <head> <link rel="stylesheet" href="<%=bb_style%>"/> <title>asdf</title> </head>
This is not a well-formed document -- not only the top-element tag is not closed, but, more importantly, because in XML the character <
isn't allowed inside of an attribute.
Therefore the document() function doesn't succeed in parsing this as an XML document and this is the problem you have.
I don't know ASP but I bet there is a better way to include stuff (such as a special include directive that's present in all good template engines and web frameworks).
The piece of XML you show is not really XML because you can't have literal angle brackets as content. You need to write them as <
and >
. This on the other hand will most likely not work with ASP because it surely relies on the exact presence of <%=
.
Process non XML trees can be done in XSLT 2.0. This stylesheet, with any input:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:analyze-string select="unparsed-text('some.asp')" regex="<title>(.*)</title>">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
Output:
asdf
With, 'some.asp' like:
<html>
<head>
<link rel="stylesheet" href="<%=bb_style%>"/>
<title>asdf</title>
</head>
</html>
精彩评论