Solved

Parsing content with XSLT to replace custom tag

Posted on 2004-04-22
14
730 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:bruno
  • 10
  • 3
14 Comments
 
LVL 18

Author Comment

by:bruno
ID: 10893970
Here is my XSLT file as it currently stands:






<?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>
0
 
LVL 10

Accepted Solution

by:
Yury_Delendik earned 250 total points
ID: 10894730
<?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:apply-templates />
     </xsl:template>
     
     <xsl:template match="@*|node()">
          <xsl:copy>
               <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
     </xsl:template>    
     
     <xsl:template match="workshop">
          <b>Hello World</b>
     </xsl:template>    
</xsl:stylesheet>
0
 
LVL 18

Author Comment

by:bruno
ID: 10895709
will try that when i get to work in the morning and report back, thanks.
0
 
LVL 15

Expert Comment

by:dualsoul
ID: 10896538
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.
0
 
LVL 18

Author Comment

by:bruno
ID: 10898334
ok, so how do i do that?
0
 
LVL 18

Author Comment

by:bruno
ID: 10899352
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>
0
 
LVL 18

Author Comment

by:bruno
ID: 10899387
points raised, need an answer quickly on how to make this work.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 10

Expert Comment

by:Yury_Delendik
ID: 10899498
<xsl:template match="workshop">
<xsl:text disable-output-escaping="yes">&lt;% </xsl:text>ecmCollection 6,"ecmNavigation"<xsl:text disable-output-escaping="yes"> %&gt;</xsl:text>
</xsl:template>
0
 
LVL 18

Author Comment

by:bruno
ID: 10899874
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?
0
 
LVL 10

Expert Comment

by:Yury_Delendik
ID: 10900316
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 http://www.experts-exchange.com/Web/Web_Languages/XML/Q_20960349.html
0
 
LVL 18

Author Comment

by:bruno
ID: 10900332
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>
0
 
LVL 18

Author Comment

by:bruno
ID: 10900369
thanks for your assistance...still new to the XML game.  trying to learn more!
0
 
LVL 18

Author Comment

by:bruno
ID: 11069607
have asked a follow up question here:

http://www.experts-exchange.com/Web/Web_Languages/XML/Q_20989663.html


thanks
0
 
LVL 18

Author Comment

by:bruno
ID: 11088823
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now