ASP

ASP

Uses

Removing formatting from JPS feeds

JPS is a database containing information about journals that Wiley Blackwell publishes. Among other jobs, it is used to store the copy for the journal-sepcific pages on the corporate web site (see, for example, the page for Archives of Drug Information). In order to display the information on (for example) author guidelines, one would include the following code snippet at the point in the page where you want the text to appear

<%Response.write JournalSubmitGet()%>

Unfortunately, the text stored in JPS, though marked-up in HTML, is fairly gross. Much of it appears to have been authored in MS Word, and little has been done to remove Word's ridiculous ideas of what consititutes good HTML.

The really fatal problem is that the tags often have style information attached to them directly (using the style attribute). This is major difficulty because the nature of the CSS cascade is such that styles attached to tags override any other styles.

<%
'function to remove all attributes from a specific tag
function ClearAttributes(InputString, Tag)
	Dim StartLocation, EndLocation, LeftString, RightString
	Dim TempString, SearchString, NewString
	' Check if there is a tag with any attributes.
	' If not, just return the supplied string
	SearchString = "<" & Tag & " "
	NewString = "<" & Tag & ">"
	Do While InStr(InputString, SearchString) > 0
		' Start of string to excise is beginning of first
		' instance of SearchString
		StartLocation = InStr(InputString, SearchString)
		' End of string to excise is first instance of ">"
		' after the StartLocation
		EndLocation = InStr(StartLocation, InputString, ">")
		' LeftString and RightString are the strings before
		' and after the opening h1 tag containing a style
		' declaration
		LeftString = Left(InputString, (StartLocation - 1))
		RightString = Mid(InputString, (EndLocation + 1))
		' Join the pieces again, replacing the tag with a
		' style declaration with a plain tag
		TempString = LeftString & NewString & RightString
		InputString = TempString
	Loop
	ClearAttributes = InputString
End function

'function to clean up output from JPS
function CleanJPSOutput(InputString)
	Dim TagsAttributesRemove, StringsRemove, item
	TagsAttributesRemove = Array ("h1", "H3", "P", "b", "B",
		"i", "I", "div", "DIV", "SPAN", "font", "FONT", "LI",
		"UL")
	For Each item in TagsAttributesRemove
		InputString = ClearAttributes(InputString, item)
	Next
	' collapse multiple instances of   into one
	Do While InStr(InputString, "  ") > 0
		InputString = Replace(InputString, "  ", " ")
	Loop
	' collapse multiple instances of   into one
	Do While InStr(InputString, "  ") > 0
		InputString = Replace(InputString, "  ", " ")
	Loop
	' collapse multiple instances of   into one
	Do While InStr(InputString, "<br />") > 0
		InputString = Replace(InputString, "<br />", " ")
	Loop
	' replace non-breaking spaces with ordinary spaces
	InputString = Replace(InputString, " ", " ")
	' remove empty paragraphs
	InputString = Replace(InputString, "<P> <P>", "<P>")
	StringsRemove = Array ("<P></P>", "<P> </P>", "</STRONG>
		<STRONG>", "<span>", "</span>", "<SPAN>", "</SPAN>",
		"<FONT>", "</FONT>", "<font>", "</font>",
		"<o:p>", "</o:p>", "<H3>", "</H3>", "<b>", "</b>",
		"<div>", "</div>", "<P></P>", "·          ",
		"<?xml:namespace prefix = o ns = ""urn:schemas-microsoft-com:office:office"" />")
	For Each item in StringsRemove
		InputString = Replace(InputString, item, "")
	Next
	' article specific fixes
	' fix overlong string in CEI author guidelines
	InputString = Replace(InputString,
		">www.blackwellpublishing.com/bauthor/English_Language.asp",
		">Blackwell Author Services")
	CleanJPSOutput = InputString
END function
%>

The call to the JPS function is wrapped in in the CleanJPSOutput() function.

<%Response.write CleanJPSOutput(JournalSubmitGet())%>

External links