Add pipe character and eliminate white space

Here should go questions about transforming XML with XSLT and FOP.
Marzipan
Posts: 12

Add pipe character and eliminate white space

Tue Mar 13, 2012 11:46 pm

Two questions.

How to get "pipe" inbetween value?
How to get rid of whitespace > 1 space?

Code: Select all

<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.8" productVersion="12.0.0" PIVersion="1.0.0.0" href="file:///C:\Documents%20and%20Settings\mbj3f\Local%20Settings\Application%20Data\Microsoft\InfoPath\Designer2\c26babb28b984f84\manifest.xsf" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?>
<my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:xhtml="http://www.w3.org/1999/xhtml"
   xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-03-12T14:44:04"
   xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us">
   <my:Metric_ID>176</my:Metric_ID>
   <my:BestPracticeGroup>
      <my:BestPracticeSection>
         <my:BestPractice>"Alarms-Utilize movement alarms:Bed alarms Chair
            alarms"</my:BestPractice>
         <my:ActionGroup>
            <my:ActionTable>
               <my:Action>one, one</my:Action>
               <my:ActionDate>2012-03-13</my:ActionDate>
               <my:ActionStatus>None</my:ActionStatus>
               <my:HiddenField>176|one, one|"Alarms-Utilize movement alarms:Bed alarms Chair
                  alarms"|2012-03-13|None</my:HiddenField>
            </my:ActionTable>
            <my:ActionTable>
               <my:Action>one, two</my:Action>
               <my:ActionDate xsi:nil="true"/>
               <my:ActionStatus>Some</my:ActionStatus>
               <my:HiddenField>176|one, two|"Alarms-Utilize movement alarms:Bed alarms Chair
                  alarms"||Some</my:HiddenField>
            </my:ActionTable>
         </my:ActionGroup>
      </my:BestPracticeSection>
      <my:BestPracticeSection>
         <my:BestPractice>"Complete central line insertion checklist in real
            time"</my:BestPractice>
         <my:ActionGroup>
            <my:ActionTable>
               <my:Action>two, one</my:Action>
               <my:ActionDate xsi:nil="true"/>
               <my:ActionStatus/>
               <my:HiddenField>176|two, one|"Complete central line insertion checklist in real
                  time"||</my:HiddenField>
            </my:ActionTable>
            <my:ActionTable>
               <my:Action>two, two</my:Action>
               <my:ActionDate>2012-03-15</my:ActionDate>
               <my:ActionStatus>Test</my:ActionStatus>
               <my:HiddenField>176|two, two|"Complete central line insertion checklist in real
                  time"|2012-03-15|Test</my:HiddenField>
            </my:ActionTable>
         </my:ActionGroup>
      </my:BestPracticeSection>
   </my:BestPracticeGroup>
</my:myFields>

Code: Select all

<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-03-12T14:44:04"> 
   
    <xsl:output method="text"/> 
    <xsl:strip-space elements="*"/>
    <xsl:param name="lf" select="'&#13;&#10;'"/> 
   
    <xsl:template match="my:HiddenField"> 
        <xsl:for-each select="descendant::*"> 
            <xsl:text>/</xsl:text> 
            <xsl:for-each select="ancestor-or-self::*"> 
                <xsl:value-of select="local-name()"/> 
                <xsl:if test="position() != last()"> 
                    <xsl:text>/</xsl:text> 
<!--                    <xsl:value-of select="'|'"/>  -->    Insert pipe btw fields?  Strip-out spaces > 1
                </xsl:if> 
            </xsl:for-each> 
            <xsl:value-of select="$lf"/> 
        </xsl:for-each> 
    </xsl:template> 
   

   
</xsl:stylesheet>
Marzipan
Posts: 12

Re: Add pipe character and eliminate white space

Wed Mar 14, 2012 4:02 pm

Found the whitespace solution, added below to xsl. Still not sure why pipe character is not appending?

<xsl:template match="text()">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
adrian
Posts: 2478

Re: Add pipe character and eliminate white space

Wed Mar 14, 2012 4:41 pm

Hi,

That character is not appending because the stylesheet never gets to that point. You have an <xsl:for-each select="descendant::*">, but my:HiddenField has no descendants, so the XSLT execution never enters that for-each block.

Use the XSLT debugger from Oxygen to see how the XSLT is executed.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 0 guests