After transformation getting output in text instead of xml nodes - xslt

My problem is after executing xlst file i am getting the output in text all in one line, but not in xml as required. My xml as well as xslt file is as follows.
<root>
<Jobs Found="10" Returned="50">
<Job ID="8000000" PositionID="600002">
<Title>Development Manager</Title>
<Summary>
<![CDATA[ An experienced Development Manager with previous experience leading a small to mid-size team of developers in a Java/J2EE environment. A hands on role, you will be expected to manage and mentor a team of developers working on a mix of greenfield and maintenance projects.   My client, a well known investment bank, requires an experienced Development Manager to join their core technology team. This t
]]>
</Summary>
<DateActive Date="2009-10-06T19:36:43-05:00">10/6/2009</DateActive>
<DateExpires Date="2009-11-05T20:11:34-05:00">11/5/2009</DateExpires>
<DateUpdated Date="2009-10-06 20:12:00">10/6/2009</DateUpdated>
<Location>
<Country>xxxx</Country>
<State>xxx</State>
<City>xxx</City>
<PostalCode>xxx</PostalCode>
</Location>
<CompanyName>abc Technology</CompanyName>
<BuilderFields />
<DisplayOptions />
<AddressType>1234</AddressType>
</Job>
</Jobs>
</root>
XSLT stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" media-type="application/xml"
cdata-section-elements="Summary"/>
<!-- default: copy everything using the identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<!-- override: for Location and Salary nodes, just process the children -->
<xsl:template match="Location|Salary">
<xsl:apply-templates select="node()"/>
</xsl:template>
<!-- override: for selected elements, convert attributes to elements -->
<xsl:template match="Jobs/#*|Job/#*">
<xsl:element name="{name()}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<!-- override: for selected elements, remove attributes -->
<xsl:template match="DateActive/#*|DateExpires/#*|DateUpdated/#*"/>
</xsl:stylesheet>
Current Output in text is:
492 50 83000003 61999998 Market-leading company With a newly created role High Profile Position With Responsibilty, Visibility & Opportunity Must Have Solid BA Skills Honed in a SDLC environment Market-leading company With a newly created role High Profile Position With Responsibilty, Visibility & Opportunity Must Have Solid BA Skills Honed in a SDLC environment My client is a market-leader who continue to go from strengt 10/5/2009 11/4/2009 10/5/2009 Australia NSW Sydney 2000 Skill Quest 90,000.00 120,000.00 Per Year AUD 6
This outout i want in xml. pls help me to get a solution.

Do you have a line like this at the top of your XSLT file??
<xsl:output method="xml" indent="yes"/>
That defines what the output format is - "text" is default, "html" and "xml" are the other options.
I don't know what you're doing, but when I run your XSLT file on the sample XML file provided, I get this as output:
<?xml version="1.0" encoding="utf-8"?>
<root>
<Jobs><Found>10</Found><Returned>50</Returned>
<Job><ID>8000000</ID><PositionID>600002</PositionID>
<Title>Development Manager</Title>
<Summary>
An experienced Development Manager with previous experience leading a small to mid-size team of developers in a Java/J2EE environment. A hands on role, you will be expected to manage and mentor a team of developers working on a mix of greenfield and maintenance projects.&#160;&#160; My client, a well known investment bank, requires an experienced Development Manager to join their core technology team. This t
</Summary>
<DateActive>10/6/2009</DateActive>
<DateExpires>11/5/2009</DateExpires>
<DateUpdated>10/6/2009</DateUpdated>
<Country>xxxx</Country>
<State>xxx</State>
<City>xxx</City>
<PostalCode>xxx</PostalCode>
<CompanyName>abc Technology</CompanyName>
<BuilderFields />
<DisplayOptions />
<AddressType>1234</AddressType>
</Job>
</Jobs>
</root>
Marc

I suspect you are watching the transformation result in a browser.
The transformation itself works perfectly, but the browser displays the plain text of the XML (since it expects HTML contents by default and ignores any tags it does not recognize, displaying their text contents only).
Try media-type="text/xml" and see if that makes any difference. If it doesn't, don't let the browser display confuse you - there is nothing wrong with the XSLT. You should use another XSLT processor to confirm/debug the XSLT.

You probably write out the inner text of an xml node instead of calling apply-templates in one of your nodes. I couldn't find your attached xsl, so it's not easy to guess. But post the xslt, and I'll tell you.

Related

docbook saxon toolchain does not recognize customization hard-page-break

I cannot get docbook tool chain to do the hard page break
as described at the end of http://www.sagehill.net/docbookxsl/PageBreaking.html
(I used to have this working for me but seem to have lost the mojo.)
Here is the script to invoke docbook and saxon
#!/bin/sh
export CLASSPATH=/home/leffstudent/saxon-6.0.1.jar:/home/leffstudent/docbook-sl-1.79.1/saxon65.jar
echo $CLASSPATH
java com.icl.saxon.StyleSheet \
-o $1.fo $1 stO.xsl \
use.extensions=1 default.table.width=auto title.margin.left=0pc insert.xref.page.number=yes
(stO.xsl also sets my ref parameters on how xref should display page numbers. That is
not working, either. Thus, I suspect that my invocation of com.icl.saxon.Stylesheet
is ignoring my customization link
Here is the test docbook file I tried. (The real files is a 500 page
class notes.)
<section><title> </title>
<para>
abc
</para>
<?hard-pagebreak?>
<para>
def
</para>
</section>
Here is the style sheet, stO.xsl
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
<xsl:import href="./titlepage.xsl"/>
<xsl:import href="/home/leffstudent/docbook-xsl-1.79.1/fo/docbook.xsl"/>
<xsl:template match="processing-instruction('hard-pagebreak')">
<fo:block break-after='page'/>
</xsl:template>
<xsl:attribute-set name="formal.object.properties">
<xsl:attribute name="keep-together.within-column">auto</xsl:attribute>
</xsl:attribute-set>
<xsl:param name="local.l10n.xml" select="document('')"/>
<l:i18n xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">
<l:l10n language="en">
<l:context name="xref">
<l:template name="section" text="%t on Page Number %p"/>
<l:template name="mediaobject" text="%t on Page Number %p"/>
<l:template name="imageobject" text="%p"/>
</l:context>
<l:context name="xref-number-and-title">
<l:template name="section" text="%t on Page Number %p"/>
<l:template name="imageobject" text="%p"/>
</l:context>
</l:l10n>
</l:i18n>
</xsl:stylesheet>
I got this working finally with XSLTPROC:
#!/bin/sh
xsltproc --output $1.fo sd.xsl $1
It prints a separate page where I have the hard-pagebreak processing instruction.
Here is the customization layer, sd.xsl
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
<xsl:import href="/home/leffstudent/docbook-xsl-1.79.1/fo/docbook.xsl"/>
<xsl:template match="processing-instruction('hard-pagebreak')">
<fo:block break-after='page'/>
</xsl:template>
</xsl:stylesheet>
I have tried again getting my xref's to work with pictures. (That, of course, is
with a larger file than sd.xsl But that is a separate issue, both literally
and figuratively.)
I still have not been able to get this working with Xalan. See
Question 55941299.
I have to check again to see if I can get this to work with saxon.
This is is what I used to use to prepare my class notes.
However, I can prepare out my 530-page class notes with xsltproc with proper page breaks.

XSLT - Extract and manipulate portion of XML data

The input XML:
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Description><![CDATA[Audience: Andrew Reed, Senior Training Specialist, Microsoft Corporation<br/>This session is for individuals who spend significant time writing and creating documents and have some familiarity with Microsoft Word.<br/>Thanks.]]></Description>
</root>
The XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/root">
<div>
<xsl:value-of disable-output-escaping="yes" select="Description"/>
</div>
</xsl:template>
</xsl:stylesheet>
I need to add a couple of more BR tags after first occurrence of BR, that's after Audience line and before other description starts.
Can you please modify my XSLT to get the desired output?
So I want output like below:
Audience: Andrew Reed, Senior Training Specialist, Microsoft Corporation
This session is for individuals who spend significant time writing and creating documents and have some familiarity with Microsoft Word.
Thanks.
It would be nice if your input data had the <br/> elements as actual elements, instead of being escaped, so that they could be selected directly using XPath.
But since they are as they are, you can use regexp replace, relying on the assumption that they will always conform to a limited range of patterns. You will often be warned not to parse XML or HTML in general using regexps, and rightly so, because regexps aren't a general solution. But for limited uses they can be sufficient.
If I've guessed your requirements correctly, you could use something like
<xsl:value-of select="replace(Description, '<[Bb][Rr] ?/?>',
'
')"/>
That will give you the sample output you showed, as opposed to adding a couple of more BR tags after first occurrence of BR. It will tolerate some variation, e.g. <br> or <BR />.
This is assuming you can use XSLT 2.0, because replace() isn't available in 1.0. If you're limited to 1.0, please let me know.

XSLT - Remove Sub Tag from results

I am looking to return the content of a particular XML Tag <para> without its sub tags <bridgehead> or <sliceXML> in the results. I am testing the following useing http://xslttest.appspot.com/ Any help is as always, much appreciated.
My XML
<para>
<bridgehead>Galaxy Zoo</bridgehead>
<sliceXML>Galaxy</sliceXML>
The human eye is far better at identifying characteristics of galaxies
than any computer. So Galaxy Zoo has called for everyday citizens to
help in a massive identification project. Well over a hundred thousand
people have helped identify newly discovered galaxies. Now you can, too.
</para>
My XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sparql-results="http://www.w3.org/2005/sparql-results#" version="1.0">
<xsl:template match="/">
<xsl:call-template name="results"/>
<xsl:message>FROM simpleHMHTransform XSLT8</xsl:message>
</xsl:template>
<xsl:template name="results">
<xsl:for-each select="//para">
<xsl:call-template name="para"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="para">
<div id="para">
<xsl:value-of select="."/>
</div>
</xsl:template>
</xsl:stylesheet>
My current results
<?xml version="1.0" encoding="UTF-8"?><div xmlns:sparql- results="http://www.w3.org/2005/sparql-results#" id="para">
Galaxy Zoo
Galaxy
The human eye is far better at identifying characteristics of galaxies
than any computer. So Galaxy Zoo has called for everyday citizens to
help in a massive identification project. Well over a hundred thousand
people have helped identify newly discovered galaxies. Now you can, too.
</div>
My desired results
<?xml version="1.0" encoding="UTF-8"?><div xmlns:sparql-results="http://www.w3.org/2005/sparql-results#" id="para">
The human eye is far better at identifying characteristics of galaxies
than any computer. So Galaxy Zoo has called for everyday citizens to
help in a massive identification project. Well over a hundred thousand
people have helped identify newly discovered galaxies. Now you can, too.
</div>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sparql-results="http://www.w3.org/2005/sparql-results#" version="1.0">
<xsl:template match="para">
<div id="para"><xsl:copy-of select="text()"/></div>
</xsl:template>
</xsl:stylesheet>

How to handle linked components in XSLT in tridion SDL Tridion 2011 SP1 using XSLT mediator

I am working on creating XSLT TBB for a component that has link to another component.
Consider my Component name is "A" which has link to another component "B".
Component A source looks like this:
<Content xmlns="Some UUID">
<Name xlink:type="simple" xlink:href="tcm:184-1897"
xmlns:xlink="http://www.w3.org/1999/xlink" xlink:title="B"></Name>
</Content>
Component B source is:
<Content xmlns="Some UUID">
<first>first filed</first>
<second>second field</second>
</Content>
Can any one help me how to write an XSLT TBB that outputs values from this linked Component?
Thank you.
In order to access fields from the linked component you will need to load it using the document function, keep i nmind that the linked component may be based on a different Schema, and as such have a different name space like this:
Component A
<Content xmlns="Some UUID">
<Name xlink:type="simple"
xlink:href="tcm:184-1897"
xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:title="B"/>
</Content>
Component B
<Content xmlns="Some Other UUID">
<Text>Some Value</Text>
</Content>
You can then transform the Component A and access the linked Component B as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:main="Some UUID"
xmlns:link="Some Other UUID"
xmlns:xlink="http://www.w3.org/1999/xlink" >
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="LINKED_COMPONENT" select="document(//main:Name/#xlink:href)"/>
<xsl:value-of select="$LINKED_COMPONENT//link:Text"/>
</xsl:template>
</xsl:stylesheet>
Note that I have used "//" in my XPath to make the code easier to read, but this is not ideal from a performance stand point.
If for some reason you will not know what Schema (and therefore namespace) the linked Component will be based on, you can also use the $LINKED_COMPONENT//*[local-name()='Text'] notation, but this again will introduce a performance hit.
Please explain what you mean by "handle this component linking".
Do you mean that you want to access this linked component and its fields within your TBB on the content manager side, or do you mean that you want to output an anchor tag in your HTML that will link to the other component on your website?
To output an image that your Component links to, have a look at this:
http://yoavniran.wordpress.com/2009/07/11/implementing-the-xslt-mediator-part-1
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:value-of select="simple:image/#xlink:href"/>
</xsl:attribute>
</xsl:element>
Edit: To output additional fields of a linked Component, see this section: http://yoavniran.wordpress.com/2009/07/11/implementing-the-xslt-mediator-part-1/#complink
An example from there:
<xsl:attribute name="alt">
<xsl:value-of select="document(simple:image/#xlink:href)/tcm:Component/tcm:Data/tcm:Metadata/image:Metadata/image:altText"/>
</xsl:attribute>
So this loads the Multimedia Component and then extracts a value from a Metadata field.
Here is XSLT code to extract some fields from multi-value component links. Keep in mind that component links belongs to the same schema.
<!-- language: xml -->
<xsl:for-each select="base:componentLink">
<xsl:element name="div">
<xsl:variable name ="LinkedComponent" select="document(./#xlink:href)"></xsl:variable>
<xsl:value-of select="$LinkedComponent/tcm:Component/tcm:Data/tcm:Content/linked:Teaser/linked:LinkText"/>
</xsl:element>
</xsl:for-each>

Order of XML Elements Using XSLT

Suppose i have an xml document like this
XML File:
<document>
<educationalsection>
educational details
</educationalsection>
<professionalsection>
professional section details
</professionalsection>
</document>
I have created XSL to converge it into my required format but the problem is if i want to change the order of the sections how can i do that? For instance if i want the professional section to come on top of educational without changing the xml, how is that possible? WHat will i need to add to my existing xsl or xml so that when my web application send the xml for transformation it can have different orders of elements as specified by the web app.
This stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="pOrder" select="'professionalsection,educationalsection'"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*">
<xsl:sort select="string-length(
substring-before(
concat(',',$pOrder,','),
concat(',',name(),',')))"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Output:
<document>
<professionalsection>
professional section details
</professionalsection>
<educationalsection>
educational details
</educationalsection>
</document>
The xsl:apply-templates and xsl:for-each elements can have xsl:sort child elements that can be used to order the child nodes that were selected. Use different sort orders whenever you need to.
You can also use the mode attribute on xsl:template to select different templates using different sort orders.