Thursday, 2 October 2014

How do I read a URL in XSL-T then pass it into a jQuery function?



Apologies in advance on this: I'm new to XSLT and jQuery, as will become obvious very soon. First I'll give the (stripped-down) contents of the files I'm using, then I'll pose my questions.


test.xml:



<?xml version="1.0" encoding="UTF-8"?>
<contentDefinition>
<contentDefinitionNode objectId="rssFeedUrl" type="textbox" label="RSS Feed URL" required="yes" translate="false">http://ift.tt/1vBp5QV;
</contentDefinition>


test.xsl:



<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output method="html" indent="yes" encoding="utf-8" omit-xml-declaration="yes"/>
<xsl:variable name="rssFeedUrl" select="//contentDefinitionNode[@objectId='rssFeedUrl']/@select" />

<xsl:template match="/">
<html>
<head>
<script src="http://ift.tt/t0Y3fx" type="text/javascript"></script>
<script src="C:\Users\me\Documents\Visual Studio 2012\Projects\ContentDemo\scripts\jquery.zrssfeed.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#test').rssfeed('$rssFeedUrl', {
});
});
</script>
</head>
<body>
<div id="test"></div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


What I'd like to do is read the rssFeedUrl from test.xml and pass it into test.xsl's rssfeed function. Running the transform in VS, I keep getting the following message: "The specified URL is invalid." I know the URL is okay, as when I pass it directly into the rssfeed function I get the feed I'm expecting. So I'm guessing it's being read from the xml file incorrectly.


I did try for quite a while to troubleshoot this myself but can't even figure out how to display what the invalid URL is. I tried inserting the following into the element but receive an error stating the variable is invalid:



<script>
function showIt() {
alert($rssFeedUrl)
};
window.onload=showIt
</script>


I'm guessing this error is because the variable is out of scope, but I'm not sure how to fix it. This is just a long way of saying I attempted to debug the URL problem, but am not sure how to even go about doing it. (I can't even figure out how to use xsl to print out the value of the to the screen.)


I'd appreciate any help. Again, I apologize if the answers to these questions are obvious. I'm pretty new to most of this.


No comments:

Post a Comment