Solved

When using XSL to transform XML for InDesign, How do I get the bold to output

Posted on 2011-03-07
7
746 Views
Last Modified: 2013-12-02
Thank you in advance for any help you can provide.

I have an XML document provided to me,  here's a snippet:

<?xml version="1.0" standalone="no"?>
<web-export>
<?whitespace-handling use-characters?>
<run-date>02/10/2011
<pub-code>UNG VP
<ad-type>CLS 6 Col Tab
<cat-code>Liner</cat-code>
<class-code>100</class-code>
<subclass-code>143</subclass-code>
<position-description>Notices</position-description>
<ad-number>0000146752-01</ad-number>
<start-date>02/10/2011</start-date>
<end-date>02/10/2011</end-date>
<line-count>6</line-count>
<run-count>1</run-count>
<customer-type>Transient</customer-type>
<account-number>151915</account-number>
<account-name>OREGON WCP STATEWIDE CLASS</account-name>
<addr-1>133 ENTERPRISE DRIVE </addr-1>
<addr-2> </addr-2>
<city>VERONA</city>
<state>WI</state>
<postal-code>53593</postal-code>
<country>USA</country>
<phone-number>6081111111</phone-number>
<fax-number></fax-number>
<url-addr></url-addr>
<email-addr></email-addr>
<pay-flag>N</pay-flag>
<ad-description>ATTENTIONDIABETICSWITHMEDICAREGETAFREETA</ad-description>
<order-source></order-source>
<order-status>Ready</order-status>
<payor-acct>151915</payor-acct>
<agency-flag>N</agency-flag>
<rate-note></rate-note>
<ad-content>
<b>ATTENTION DIABETICS </b>with Medicare.  Get a FREE Talking Meter and diabetic supplies at NO COST plus FREE home delivery!  Best of all, this meter eliminates painful finger pricking!  Call 1-888-667-5202 (wcan)</ad-content>
</ad-type>

I need to pull the data out of it that I need (not all) and apply formatting. I also don't want any repeating heads. I have accomplished this much with XSL.

What I can't get is the bold tag, within the ad-content tag to show up in the output.

Here is the XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
 
<!--Container Element -->
<xsl:element name="ad-type">
 
<!--Start loooping through XML data -->
 <xsl:for-each select="web-export/run-date/pub-code/ad-type">
     
<!--Set up elements. Do not ouput subclass-code and position-description dups-->
<subclass-code>
                  <xsl:value-of select='concat(subclass-code[not(.=preceding::subclass-code)], " ", position-description[not(.=preceding::position-description)])'/>
      </subclass-code>
     
<!--Carriage Return -->
      <xsl:text>&#13;</xsl:text>
     
<!--Add ad content -->
      <ad-content><xsl:value-of select="ad-content"/>
      </ad-content>

<!--Carriage Return -->    
     <xsl:text>&#13;</xsl:text>
     
</xsl:for-each>
</xsl:element>
</xsl:template>      
</xsl:stylesheet>

0
Comment
Question by:charthumser
  • 4
  • 3
7 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35062350
short answer:
replace this
<ad-content><xsl:value-of select="ad-content"/>
      </ad-content>
by this
<xsl:copy-of select="ad-content"/>

value of will only show the text nodes
copy-of will make a deep copy
     
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 125 total points
ID: 35062436
long answer,
it is always better to avoid for-each in favour of apply-templates if you can
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:template match="/">
        <!--Container Element -->
        <xsl:element name="ad-type">
            <!--Start loooping through XML data -->
            <xsl:apply-templates select="web-export/run-date/pub-code/ad-type"/>
        </xsl:element>
    </xsl:template>  
    
    <xsl:template match="ad-type">
        <!--Set up elements. Do not ouput subclass-code and position-description dups-->
        <subclass-code>
            <xsl:value-of select='concat(subclass-code[not(.=preceding::subclass-code)], " ", position-description[not(.=preceding::position-description)])'/>
        </subclass-code>
        
        <!--Carriage Return -->
        <xsl:text>&#13;</xsl:text>
        
        <!--Add ad content -->
        <ad-content><xsl:apply-templates select="ad-content/node()"/>
        </ad-content>
        
        <!--Carriage Return -->    
        <xsl:text>&#13;</xsl:text>
        
    </xsl:template>
    
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:charthumser
ID: 35062443
Wow. you've got to be kidding?!

Will that take care of italics and underlines too?

Actually, it's a bit flakey...it doesn't always end the bold.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35062461
it takes care of all the deeper nodes, italics and underline too

do you mean that your source is not well formed?
what is flakey?
0
 

Author Closing Comment

by:charthumser
ID: 35062464
wow.
0
 

Author Comment

by:charthumser
ID: 35062554
I meant that it wasn't always ending the bold where it was supposed to, it would bold the whole paragraph instead of just the word(s) between the tags.

Your revised code worked perfectly. I posted the flaky comment before I seen your code.

One more question, I have a carriage return after the subclass-code because without it, the Paragraph marker was applying the style from the next element. Any ideas?

I really appreciate the help, I was pulling my hair out on this one.

0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35062584
OH, I see,
I have no clue about the paragraph marker
depends on how you look at the result
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

705 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

15 Experts available now in Live!

Get 1:1 Help Now