tags:

views:

25

answers:

3

I have 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.

A: 

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 &lt; and &gt;. This on the other hand will most likely not work with ASP because it surely relies on the exact presence of <%=.

musiKk
Can I use <%= inside of attribute by setting something up or it is impossible?
Artic
I think it's impossible. `xmlwf` says the file is not valid. And in XML it's either valid and you can work with it or it's not and that's it. Doesn't the approach with includes work for you?
musiKk
+1  A: 
  <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.

Dimitre Novatchev
A: 

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"&gt;
    <xsl:output method="text"/>
    <xsl:template match="/">
        <xsl:analyze-string select="unparsed-text('some.asp')" regex="&lt;title>(.*)&lt;/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>    
Alejandro