We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

XSLT + XML reference documentation

Is there a reference manual or something that outlines what tags are available? I need to know which tags to use for

bolding text
creating clickable hyperlinks (standard html anchor tag did not work)

I am also curious if there would be anyway for the pdf to render dynamic html injections (this is not as important, but a customer has existing data that was formatted with HTML and would like to keep it if possible).

@zach.schreiber

Are you asking for XML Tags? Please check the supported XML Schema in the API documentation to determine about supported XML Tags.

We need to investigate the possibility of your above requirement. Would you please share sample source and expected output files with us in .zip format so that we can test the scenario in our environment and address it accordingly?

@asad.ali

In my XSLT, I added this

		<text Alignment="Center" LineSpacing="1">
			<segment FontSize="10" FontName="Helvetica">
				
                <strong>Bold</strong>

			</segment>
		</text>

It does not error when rendering, but the text does not show up. The text does show up if I remove the strong tags, but it is not bolded, of course.

And perhaps I missed it, but I don’t see how to add a hyperlink.

@zach.schreiber

There are two ways to have the text bold. You can either specify the FontStyle = "Bold" attribute in the XML Tag or use a HtmlFragment to bold the text using HTML Tags. Please try to check the examples given in the following documentation topics and let us know in case you still face any issues:

@asad.ali

Hi, I believe the issue I am having is that with the implementation I am having to use, I don’t have access to the XML side of things. I only have access to edit the XSLT file. From what I can see, the only way to use the FontStyle or HtmlFragment is directly in the XML, not in the XSLT, is that correct? If there is some way to place the HtmlFragment into the XSLT and have that get translated into the generated XML, that would be absolutely fantastic!

I am also still curious about how to embed a hyperlink into the PDF, if that is possible.

Here is a sample XSLT file I have that I am using to test things

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">

<!-- OBJECTS -->
<xsl:variable name="ClaimLineItem" select="'OT.ClaimLineItem'" />

<!-- ACTUAL PAGE BEGINS HERE  -->
<xsl:template match="/object">
	<Pdf xmlns="Aspose.Pdf">
		<Section PageSize="letter" IsLandscape="false" PageMarginLeft="45" PageMarginRight="45" FontName="Arial">
		
			<!-- HEADER -->
			<Header DistanceFromEdge="45">

				<Text Alignment="Center" LineSpacing="4.5">
					<Segment FontSize="14" FontName="Helvetica">
						PDF Rendition Test 
					</Segment>
				</Text>
			</Header>

			<!-- TESTING DIRECT PROPERTY CALL -->
			<text Alignment="Center" LineSpacing="1">
				<segment FontSize="10" FontName="Helvetica">
					DIRECT PROPERTY CALL
					<hr />
					<xsl:value-of select="/object/properties/prop[@id=0]/value"/>					
				</segment>
			</text>

			<!-- TESTING DIRECT REFERENCE PROPERTY CALL -->
			<text Alignment="Center" LineSpacing="1">
				<segment FontSize="10" FontName="Helvetica">
					<xsl:value-of select="/object/direct-references/object[@objtype-aliases=$ClaimLineItem]/properties/prop[@id=0]/value"/>
				</segment>
			</text>

			<!-- LOOPING THROUGH DIRECT REFERENCES WITHOUT TEMPLATE -->
			<xsl:for-each select="/object/direct-references/object[@objtype-aliases=$ClaimLineItem]">
				<text Alignment="Center" LineSpacing="1">
					<segment FontSize="10" FontName="Helvetica">
						<xsl:value-of select="properties/prop[@id=0]/value"/>
					</segment>
				</text>
			</xsl:for-each>

			<!-- LOOPING THROUGH DIRECT REFERENCES WITH TEMPLATE -->
			<xsl:for-each select="/object/direct-references/object[@objtype-aliases=$ClaimLineItem]">
				<xsl:call-template name="loopTest">
					<xsl:with-param name="item" select="."/>							
				</xsl:call-template>
			</xsl:for-each>
			
		</Section>
	</Pdf>
</xsl:template>


<xsl:template name="loopTest">
	<xsl:param name="item" />
	
	<text Alignment="Center" LineSpacing="1">
		<segment FontSize="10" FontName="Helvetica">
			<xsl:value-of select="$item/properties/prop[@id=0]/value"/>
		</segment>
	</text>
</xsl:template>

</xsl:stylesheet>

@zach.schreiber

Thanks for sharing further details. You also must have some XML file (that you cannot edit or control) along with this XSLT Style Sheet in order to generate an output PDF. Would you please share the following:

  • Respective XML source file
  • Sample Code snippet that you are using to generate the PDF
  • Generated PDF document
  • Expected output PDF document

That is the problem I do not have access to see those things in the environment I am in. An external program generates the XML data file, merges it with the XSLT, and then spits out the output. I don’t have access to anything except the XSLT and the output PDF.

@zach.schreiber

We are checking the feasibility of your requirements and will get back to you shortly.

@zach.schreiber

You can surely achieve your requirements by modifying only XSLT file. However, it looks like you are using an older version of the API which implements Aspose.Pdf.Generator approach and follows different XML Schema. Please note that old legacy approach has been removed and discontinued already and we are not providing any support related to it neither are we fixing any issues in it.

The latest version(s) of the API use DOM (Document Object Model) approach and support the XML Schema which link we already had shared with you. Using that XML Schema, please check the following sample XSLT and XML along with generated output PDF:

Input XSLT

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="text()"/>
    <xsl:template match="/Contents">
    <html>
      <Document xmlns="Aspose.Pdf" IsAutoHyphenated="false">
        <PageInfo>
          <Margin Left="5cm" Right="5cm" Top="3cm" Bottom="15cm" />
        </PageInfo>
        <Page id="mainSection">
          <TextFragment>
            <TextSegment>
              <xsl:value-of select="Content"/>
            </TextSegment>
          </TextFragment>
		  
          <HtmlFragment>
		  <![CDATA[
           <a href="https://aspose.com">
          ]]>
              <xsl:value-of select="HyperlinkText"/>
	      <![CDATA[
           </a>
          ]]>
          </HtmlFragment>
		  
		  <TextFragment>
		   <TextState Font = "Arial" FontSize="8" LineSpacing="4" FontStyle="1" />
            <TextSegment>
             <xsl:value-of select="BoldText"/>
            </TextSegment>
          </TextFragment>
        </Page>
      </Document>
    </html>
</xsl:template>
</xsl:stylesheet>

Input XML

<?xml version="1.0" encoding="utf-8" ?>
<Contents>
  <Content>Hello World!</Content>
  <HyperlinkText>Aspose</HyperlinkText>
  <BoldText>Pty Ltd.</BoldText>
</Contents>

Code

var pdf = new Document();
pdf.BindXml(dataDir + "input.xml", dataDir + "input.xslt");
pdf.Save(dataDir + "SampleOut.pdf");

SampleOut.pdf (216.4 KB)