bruno
asked on
Parsing content with XSLT to replace custom tag
Hi folks,
Here is what I am trying to do:
I have a block of text within a database that I am feeding out to a page. Within that text block, I have a "custom tag" ----
<workshop />
What I'd like to do is parse that block of content through an XSLT (i've got this part working already) and replace that <workshop /> tag with some other text.
I current have it printing out the other text, but it's not coming through at the same place in the code where the custom tag was - it's either writing above or below the content block depending on my .xsl file. I will post my XSL file below, and any help is appreciated.
Please don't be surprised if my current file is not the correct way to do things - i'd be very surprised if it was correct at all.
THanks for your assistance,
bruno
Here is what I am trying to do:
I have a block of text within a database that I am feeding out to a page. Within that text block, I have a "custom tag" ----
<workshop />
What I'd like to do is parse that block of content through an XSLT (i've got this part working already) and replace that <workshop /> tag with some other text.
I current have it printing out the other text, but it's not coming through at the same place in the code where the custom tag was - it's either writing above or below the content block depending on my .xsl file. I will post my XSL file below, and any help is appreciated.
Please don't be surprised if my current file is not the correct way to do things - i'd be very surprised if it was correct at all.
THanks for your assistance,
bruno
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
will try that when i get to work in the morning and report back, thanks.
hm....why not to use RegularExpression for this?
if you only need to find some text (<workshop />) and replace it with another RegularExpression will be much faster, clear and easier.
XSLT is for transforming, but if you don't want to transform anything, it's only waste of resources.
if you only need to find some text (<workshop />) and replace it with another RegularExpression will be much faster, clear and easier.
XSLT is for transforming, but if you don't want to transform anything, it's only waste of resources.
ASKER
ok, so how do i do that?
ASKER
Ok, so I tried this, and it broke:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="workshop">
<% ecmCollection 6,"ecmNavigation" %>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="workshop">
<% ecmCollection 6,"ecmNavigation" %>
</xsl:template>
</xsl:stylesheet>
ASKER
points raised, need an answer quickly on how to make this work.
<xsl:template match="workshop">
<xsl:text disable-output-escaping="y es"><% </xsl:text>ecmCollection 6,"ecmNavigation"<xsl:text disable-output-escaping="y es"> %></xsl:text>
</xsl:template>
<xsl:text disable-output-escaping="y
</xsl:template>
ASKER
Ok, that is now writing out my ASP to the page, but not executing it...not much better than if I just put the asp code into the database itself.
am i going about this the wrong way? do you understand what I am trying to do?
am i going about this the wrong way? do you understand what I am trying to do?
It's normal. XML can be reused in different solutions rather than ASP.
About execution: it's harder:
- You can create temporary asp page (with temporary name) and call Server.Execute (will be a pain to pass variables).
- Split result of XSLT on strings and code using as delimiters "<%" and "%>" and then output strings and execute code using VBScript's Execute statement
- Also look at https://www.experts-exchange.com/questions/20960349/call-vbscript-functions-in-xml-or-xsl.html
About execution: it's harder:
- You can create temporary asp page (with temporary name) and call Server.Execute (will be a pain to pass variables).
- Split result of XSLT on strings and code using as delimiters "<%" and "%>" and then output strings and execute code using VBScript's Execute statement
- Also look at https://www.experts-exchange.com/questions/20960349/call-vbscript-functions-in-xml-or-xsl.html
ASKER
Got it working, didn't realize i could just make my xslt into an asp page and do it that way...
points go to Yury for getting the content into the right place.
here is my file now:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="workshop">
<% ecmCustomCollection 14,"ecmWorkshops" %>
</xsl:template>
</xsl:stylesheet>
points go to Yury for getting the content into the right place.
here is my file now:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="workshop">
<% ecmCustomCollection 14,"ecmWorkshops" %>
</xsl:template>
</xsl:stylesheet>
ASKER
thanks for your assistance...still new to the XML game. trying to learn more!
ASKER
have asked a follow up question here:
https://www.experts-exchange.com/questions/20989663/Passing-a-value-from-an-xml-tag-into-an-ASP-function-within-an-XSLT.html
thanks
https://www.experts-exchange.com/questions/20989663/Passing-a-value-from-an-xml-tag-into-an-ASP-function-within-an-XSLT.html
thanks
ASKER
ASKER
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Ektron revision date: 2002-11-12 -->
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:copy-of select="node()"/>
<xsl:apply-templates select="//workshop"/>
<xsl:apply-templates select="body/node()"/>
</xsl:template>
<xsl:template match="workshop">
<b>Hello World</b>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>